我有一个包含多个项目的仓库,而且还有不同框架/技术中的API。
我有多个jenkins管道设置来满足所有这些工作,并在舞台上处理条件以例如使用跳过它们。
when {
changeset "**servicelayer/*"
}
以上是一种情况,如果有人将文件检入特定文件夹,则我不想执行完整的管道。但这仅允许跳过特定阶段。有没有办法可以在管道级别上验证是否满足条件,然后跳过整个工作?
注意:我已经尝试在Jenkins管道级别配置包含/排除区域。这对我根本不起作用。
答案 0 :(得分:0)
已经有一段时间了,我解决了这个问题,但是忘记了发布答案。将来可能会对某人有所帮助。更正它或添加评论以寻求更好的解决方案,如果发现成功,我将很乐意使用它。
要解释此处添加一些注释的步骤
stage('Validation') {
steps {
//Moving in to the directory to execute the commands
dir('servicelayer') {
script {
//Using the git command to check the difference between previous successful commit. ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} is an environment variable comes with GIT Jenkins plugin
//There is a drawback though, if it is the first time you are running this job, this variable is not available and fails the build
//For the first time i had to use ${env.GIT_COMMIT} itself at both places to pass the build. A hack but worth it for future builds.
def strCount = sh(returnStdout: true, script: "git diff --name-only ${env.GIT_COMMIT} ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} | grep servicelayer | wc -l").trim()
if(strCount=="0") {
echo "Skipping build no files updated"
CONTINUE_BUILD = false
} else {
echo "Changes found in the servicelayer module"
}
}
}
}
}
stage('Installation') {
when {
expression { return params.FORCE_BUILD || CONTINUE_BUILD }
}
steps {
dir('servicelayer') {
nodejs(nodeJSInstallationName:"${NODEJS_INSTALLATION_NAME}", configId:"${NODEJS_CONFIG_ID}") {
sh 'npm install --progress=false'
}
}
}
}