我想在中定义构建触发器Jenkinsfile
。我知道如何为BuildDiscarderProperty执行此操作:
properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '50', artifactNumToKeepStr: '20']]])
Run Code Online (Sandbox Code Playgroud)
构建另一个项目后,如何设置启动作业的构建触发器。我在Java API文档中找不到合适的条目。
编辑:我的解决方案是使用以下代码:
stage('Build Agent'){
if (env.BRANCH_NAME == 'develop') {
try {
// try to start subsequent job, but don't wait for it to finish
build job: '../Agent/develop', wait: false
} catch(Exception ex) {
echo "An error occurred while building the agent."
}
}
if (env.BRANCH_NAME == 'master') {
// start subsequent job and wait for it to finish
build '../Agent/master', wait: true
}
}
Run Code Online (Sandbox Code Playgroud)