我想在Jenkinsfile
中定义构建触发器。我知道如何为BuildDiscarderProperty做到这一点:
properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy: [$class: 'LogRotator', numToKeepStr: '50', artifactNumToKeepStr: '20']]])
如何构建另一个项目时,如何设置启动作业的Build Trigger。我在Java API docs中找不到合适的条目。
编辑: 我的解决方案是使用以下代码:
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
}
}
答案 0 :(得分:3)
我只是找了同样的事情,发现了Jenkinsfile
in jenkins-infra/jenkins.io
简而言之:
properties([
pipelineTriggers([cron('H/30 * * * *')])
])