测试套件完成后,Jenkins可以返回0和1吗?

时间:2016-06-13 07:57:03

标签: jenkins

我的查询与Jenkins服务器有关。 我已经创建了一个API来访问Jenkins服务器,Jenkins启动测试套件。

我的问题是:如果任何测试用例失败,Jenkins服务器可以返回0,否则返回1

API网址的格式为

JENKINS_URL/job/Encore_Automation/build?token=TOKEN_NAME

1 个答案:

答案 0 :(得分:1)

通过查看Build Triggers / Trigger builds remotely (e.g., from scripts),似乎此选项仅支持对项目进行排队,并且不允许您检索结果。

Jenkins REST API

从REST API调用触发构建之后,您可以开始连续的REST API调用来检查它的状态。

Jenkins CLI

然而Jenkins提供了一个jenkins-cli工具,它不仅可以触发构建,还可以等到它完成:

java -jar jenkins-cli.jar -s http://localhost:8080/ build JOB [-c] [-f] [-p] [-r N] [-s] [-v] [-w]
Starts a build, and optionally waits for a completion.
Aside from general scripting use, this command can be
used to invoke another job from within a build of one job.
With the -s option, this command changes the exit code based on
the outcome of the build (exit code 0 indicates a success)
and interrupting the command will interrupt the job.
With the -f option, this command changes the exit code based on
the outcome of the build (exit code 0 indicates a success)
however, unlike -s, interrupting the command will not interrupt
the job (exit code 125 indicates the command was interrupted).
With the -c option, a build will only run if there has been
an SCM change.

 JOB : Name of the job to build
 -c  : Check for SCM changes before starting the build, and if there's no
       change, exit without doing a build
 -f  : Follow the build progress. Like -s only interrupts are not passed
       through to the build.
 -p  : Specify the build parameters in the key=value format.
 -s  : Wait until the completion/abortion of the command. Interrupts are passed
       through to the build.
 -v  : Prints out the console output of the build. Use with -s
 -w  : Wait until the start of the command