具有Nightly部署的主分支的声明性Jenkins管道

Gue*_*135 6 git nightly-build jenkins

我想将一些工作转换为新的Jenkins 2.0声明性管道.目前他们有3个不同的工作:

  1. CI - > PollSCM每5分钟(只有主人),构建和运行测试.
  2. 明亮 - >每晚运行(构建,测试,集成测试并在夜间服务器上部署)
  3. Sprintly - >这是一个参数化的作业,每周四使用手动创建的标签运行.(在sprintly服务器上构建,测试,集成测试和部署)

为此,我在春天有一个带有maven的小项目,这将是我开始的最好的例子(简单,容易和快速建立).

目前我已经有了一个用于CI构建的Multibranch管道,但是我希望将这个工作整合到Nightly和Sprintly构建中.

  • 每晚:在夜间通过主分支运行Cron作业以部署在夜间服务器中.
  • Sprintly:构建在我的主分支中生成的Sprintly_tag,以部署在Sprintly Server中.

目前我有这个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"'
    }
}
Run Code Online (Sandbox Code Playgroud)

当某些东西被拉到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"'
        }
    }
Run Code Online (Sandbox Code Playgroud)

Gue*_*135 5

四个月后,在阅读了我自己的问题后,我意识到我尝试设置触发器和作业的方式完全错误。我们应该有 3 个不同的工作:

  1. 多分支管道将在每个分支中运行 Maven 构建(可以配置为每 n 分钟轮询一次 scm 或由存储库中的 webhook 启动。
  2. 管道(称为 nightly)将配置为在夜间触发(在作业配置中,不在管道中)并将部署到每晚系统并仅使用 master 分支(也在 Jenkins 作业中配置)
  3. 管道(称为 sprintly)但参数化为使用特定标签运行并仅使用主分支

管道应保持简单,例如:

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"'
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您有任何问题,请告诉我,我将很乐意为您提供帮助 :)