【问题标题】:Jenkins: Create a pull request on GitHub and merge it to the main branchJenkins:在 GitHub 上创建拉取请求并将其合并到主分支
【发布时间】:2021-10-03 16:45:16
【问题描述】:

我正在构建一个每小时运行一次并检查更改以进行测试的管道。我希望它仅在已进行新提交(尚未实施)时才构建和测试项目。但是,如果测试通过,我想从我测试的暂存分支创建一个拉取请求到主分支并合并更改。

我该怎么做呢?到目前为止,这是我的管道:

pipeline {
    agent any
    stages {
        stage('Pull Source Code') {
            steps {
            
                git branch: "staging", credentialsId: '58315ff7-085f-4213-b071-e0b72ba94ff9', url: 'https://github.com/DevonXDal/Reverse-Makerspace'
            }
        }
        stage('Insert Environment Variables') {
            steps {
            
                withCredentials([file(credentialsId: '3d2deb8f-69c5-4d22-a475-0d981a34574d', variable: 'envfile')]) {
                    sh "cp \$envfile ${WORKSPACE}/test.env"
                }
            }
        }
        stage('Docker Build'){
            steps{
                sh '/usr/local/bin/docker-compose -f docker-compose.Test.yml build --no-cache' 
            }
        }
        stage('Test the Project'){
            steps{
                sh '/usr/local/bin/docker-compose -f docker-compose.Test.yml down || true'
                sh '/usr/local/bin/docker-compose -f docker-compose.Test.yml up'
                sh 'y || true'
            }
        }
    }
    post {
        always {
            sh '/usr/local/bin/docker-compose -f docker-compose.Test.yml down || true'
            sh '/usr/bin/docker image prune -a --filter "until=48h"'
            sh 'y || true'
            sh '/usr/bin/docker volume rm reversemakerspacetesting_db-data-test'
        }
    }
}

我看到一些教程使用已经打开的拉取请求来合并更改,但是如何从管道创建新的拉取请求并将其合并?

【问题讨论】:

    标签: github jenkins jenkins-pipeline


    【解决方案1】:

    您可以使用变量在 Jenkins 中获取 git 分支名称。 通过使用该变量,您可以根据您的情况在 Jenkins 管道中使用 if 条件。

    if (env.BRANCH_NAME.startsWith("your branch name"))
    

    【讨论】:

      猜你喜欢
      • 2020-02-12
      • 2021-12-26
      • 2017-03-15
      • 2021-01-10
      • 1970-01-01
      • 2023-02-23
      • 2017-12-20
      • 2022-07-06
      • 1970-01-01
      相关资源
      最近更新 更多