由于 Jenkins Pipeline 存在一个限制,即您无法在不挂起构建的情况下添加手动构建步骤(例如,参见这个stackoverflow 问题),我正在尝试使用Job DSL plugin组合 Jenkins Pipeline 和Build Pipeline Plugin。
我的计划是创建一个作业 DSL 脚本,它首先执行 Jenkins 管道(在 a 中定义Jenkinsfile
),然后创建一个部署到生产环境的下游作业(这是手动步骤)。我创建了这个 Job DSL 脚本作为测试:
pipelineJob("${REPO_NAME} jobs") {
logRotator(-1, 10)
def repo = "https://path-to-repo/${REPO_NAME}.git"
triggers {
scm('* * * * *')
}
description("Pipeline for $repo")
definition {
cpsScm {
scm {
git {
remote { url(repo) }
branches('master')
scriptPath('Jenkinsfile')
extensions { } // required as otherwise it may try to tag the repo, which you may not want
}
}
}
}
publishers {
buildPipelineTrigger("${REPO_NAME} deploy to prod") {
parameters {
currentBuild()
}
}
}
}
freeStyleJob("${REPO_NAME} deploy to prod") {
}
buildPipelineView("$REPO_NAME Build Pipeline") {
selectedJob("${REPO_NAME} jobs")
}
whereREPO_NAME
被定义为环境变量。Jenkinsfile
看起来像这样:
node {
stage('build'){
echo "building"
}
stage('run tests'){
echo "running tests"
}
stage('package Docker'){
echo "packaging"
}
stage('Deploy to Test'){
echo "Deploying to Test"
}
}
问题在于,在“构建管道插件”视图中,指向的selectedJob
点"${REPO_NAME} jobs"
似乎不是“初始作业”的有效选项(您也不能手动选择它)。
有解决方法吗?即如何使用 Jenkins 管道作为构建管道插件的“初始作业”?