开发者

Launch shell scripts from Jenkins

I'm a complete newbie to Jenkins. I'm trying to get Jenkins to monitor the execution of my shell script so i that i don't have to launch them manually each time but i can't figure out how to do i开发者_如何转开发t. I found out about the "monitor external job" option but i can't configure it correctly. I know that Jenkins can understand Shell script exit code so this is what i did :

test1(){
ls /home/user1 | grep $2
case $? in
    0) msg_error 0 "Okay."
        ;;
    *) msg_error 2 "Error."
        ;;
esac
}

It's a simplified version of my functions. I execute them manually but i want to launch them from Jenkins with arguments and get the results of course. Can this be done ?

Thanks.


You might want to consider setting up an Ant build that executes your shell scripts by using Ant's Exec command:

http://ant.apache.org/manual/Tasks/exec.html

By setting the Exec task's failonerror parameter to true, you can have the build fail if your shell script returns an error code.


To use parameters in your shell you can always send them directly. for example:

  1. Define string parameter in your job Param1=test_param
  2. in your shell you can use $Param1 and it will send the value "test_param"

Regarding the output, everything you do under the shell section will be only relevant to the session of the shell. you can try to return your output into a key=value txt file in the workspace and inject the results using EnvInject Plugin. Then you can access the value as if you defined it as a parameter for the job. In the example above, after injecting the file, executing shell echo $Param1 will print "test_param"

Hope it's helpful!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜