【问题标题】:Is there a way to run multiple jobs in single pipeline有没有办法在单个管道中运行多个作业
【发布时间】:2019-08-27 21:43:41
【问题描述】:

我已经在我的 Jenkins 中配置了多个作业。例如:假设我在 Jenkins 中配置了 A、B 和 C 作业。现在我每次都必须手动运行这三个作业。我想运行一个运行所有这三个作业(A、B、C)的作业。有没有办法在管道工作中实现这一目标?请指教

【问题讨论】:

  • 这正是管道的目的。那你的问题到底是什么?
  • @ArnaudClaudel 我明白这一点。但是当我说 10 - 20 个工作时,我不能手动运行所有工作。所以这样可以节省很多时间。请注意,这仍然是通过聚合它们单独运行作业。
  • 我的意思是,管道是针对这类问题的。所以我不明白你的问题,因为解决方案只是使用普通管道。

标签: jenkins jenkins-pipeline


【解决方案1】:

是的,您可以在一个管道中运行所有三个作业。这是我们使用的一个简短的管道示例,因此用户可以选择应该运行哪个子作业(默认所有复选框都已选中):

node {
    properties([
            buildDiscarder(
                    logRotator(
                            artifactDaysToKeepStr: '',
                            artifactNumToKeepStr: '10',
                            daysToKeepStr: '',
                            numToKeepStr: '10')
            ),
            parameters([
                    booleanParam(defaultValue: true,
                            description: 'Select true to include run of Job A',
                            name: 'JOBA'),
                    booleanParam(defaultValue: true,
                            description: 'Select true to include run of Job B.',
                            name: 'JOBB'),
                    booleanParam(defaultValue: true,
                            description: 'Select true to include run of Job C',
                            name: 'JOBC')
            ])
    ])


    try {


        if (params.JOBA == true) {
            stage('Run job A') {
                build job: 'PATHTOJOBA', propagate: true, wait: true
            }
        }

        if (params.JOBB == true) {
            stage('Run job B') {
                build job: 'PATHTOJOBB', propagate: true, wait: true
            }
        }

        if (params.JOBC == true) {
            stage('Run job C') {
                build job: 'PATHTOJOBC', propagate: true, wait: true
            }
        }
--------

PATHTOJOB 是您要运行的作业的全名。使用<yourJenkinsHost>/pipeline-syntax/ 生成一个脚本,并使用Sample step > build: Build a job 来确定您的作业路径是否正确 + 它会生成可以传递给该作业的参数(如果已配置)。

阅读更多documentation here。如果所有三个作业都可以独立运行,建议您并行运行作业以节省时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多