git - 使用 Jenkinsfile 一个分支中的多个管道

标签 git jenkins jenkins-pipeline

有没有办法为一个分支存储库创建两个不同的管道? 目前我有一个 Jenkinsfile,它是使用 Jenkins GUI 手动构建的。我想创建第二个 Jenkinsfile,它也将通过 Jenkins GUI 构建,但我不知道如何将这两个管道放在同一个分支中并构建我想要的任何一个。

最佳答案

您可以使用声明式管道来执行此操作。在你的 repo 中创建两个文件,比如 firstPipeline.groovy 和 secondPipeline.groovy,如下所示,并使用你想要构建的那个配置你的 jenkins 作业:

enter image description here

firstPipeline.groovy:

pipeline {
    stages {
        stage('stage 1') {
            steps {
                script{
                    //do your things of first pipeline stage
                }
            }
        }
        stage('stage 2') {
            steps {
                script{
                    //do your things of first pipeline stage
                }
            }
        }
    }
}

secondPipeline.groovy:

pipeline {
    stages {
        stage('stage 1') {
            steps {
                script{
                    //do your things of second pipeline stage
                }
            }
        }
        stage('stage 2') {
            steps {
                script{
                    //do your things of second pipeline stage
                }
            }
        }
    }
}

关于git - 使用 Jenkinsfile 一个分支中的多个管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51932696/

相关文章:

git - 无法从 bitbucket 中提取或推送代码

amazon-web-services - 重新启动后删除Jenkinw配置

java - 使用 Jenkins 发送电子邮件收到以下错误响应

git - Jenkins 管道 : How to build new artifacts only if has a new commit

git - SSH git ls-remote 不起作用但 git clone 可以吗?

Jenkins dsl 管道 def 变量

jenkins - Jenkins 管道中的参数是否区分大小写?

Xcode 复制我的存储库并将其位置重命名为小写

git - git-svn 的钩子(Hook)

git clone "fatal: I don' t handle protocol 'ssh' "