我想将一些工作转换为新的Jenkins 2.0声明性管道。目前他们有3个不同的工作:
为此,我在春天有一个带有maven的小项目,这将是我开始的最好的例子(简单,容易和快速建立)。
目前我已经有了一个用于CI构建的Multibranch管道,但我希望将这个工作整合到Nightly和Sprintly构建中。
目前我有这个JenkinsFile
pipeline {
agent {
label 'master'
}
tools {
maven "Apache Maven 3.3.9"
jdk "Java JDK 1.8 U102"
}
triggers {
cron ('H(06-08) 01 * * *')
pollSCM('H/5 * * * *')
}
stages {
stage('Build') {
steps {
sh 'mvn -f de.foo.project.client/ clean package'
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: '**/target/*.war'
}
}
}
stage('Deploy') {
sh 'echo "Deploy only master"'
}
}
当某些东西被拉到Git时它会运行每个分支,并且在夜晚运行大约1点钟(但仍然运行所有分支)。
有任何想法或暗示吗?不需要执行部署的代码我只想知道如何在同一个JenkinsFile中过滤/拆分这些分支
非常感谢大家!
编辑:我也可以使用但它会在晚上运行所有分支(我可以只为Cron作业制作这个过滤器吗?)
stage('DeployBranch') {
when { branch 'story/RTS-525-task/RTS-962'}
steps {
sh 'echo "helloDeploy in the branch"'
}
}
stage('DeployMaster') {
when { branch 'master'}
steps {
sh 'echo "helloDeploy in the master"'
}
}
在四个月后阅读我自己的问题之后,我意识到我在尝试设置触发器和工作时完全错了。我们应该有3个不同的工作:
管道应保持简单,如:
pipeline {
agent {
label 'master'
}
tools {
maven "Apache Maven 3.3.9"
jdk "Java JDK 1.8 U102"
}
stages {
stage('Build') {
steps {
sh 'mvn -f de.foo.project.client/ clean package'
}
post {
always {
junit allowEmptyResults: true, testResults: '**/target/surefire-reports/*.xml'
archiveArtifacts allowEmptyArchive: true, artifacts: '**/target/*.war'
}
}
}
stage('Deploy') {
when (env.JOB_NAME.endsWith('nightly')
sh 'echo "Deploy on nighlty"'
when (env.JOB_NAME.endsWith('sprintly')
sh 'echo "Deploy only sprintly"'
}
}
如果您有任何问题,请告诉我,我将很乐意为您提供帮助:)