【问题标题】:jenkins choice parameterized branch checkout pipeline詹金斯选择参数化分支结帐管道
【发布时间】:2018-10-25 13:54:30
【问题描述】:

您好,我最近说过学习管道,谁能帮我编写用于选择参数化分支签出的管道,如果我签出 master 分支,则部署到某个 S3 位置,否则如果 dev 分支到某个其他位置。我试过了,但在这里失败了,谁能帮帮我。pipeline { agent any parameters { choice( name: 'BRANCH', choices: 'Development\nrelease/release_QA\nmaster', description: 'Selct the branch to deploy to repective Airflow') } stages { stage('checkout code') { steps { git(url: 'https://bitbucket.nike.com/scm/something.git', branch: '${params.BRANCH}', credentialsId: '4db2-aec4-7d5e86c4ff4b', changelog: true) sh 'ls -al' } } } }

我收到以下错误,

 +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/${params.BRANCH}^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/${params.BRANCH}^{commit} # timeout=10
 > git rev-parse origin/${params.BRANCH}^{commit} # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: Couldn't find any revision to build. Verify the repository and branch configuration for this job.
Finished: FAILURE

还请帮助我如何编写 if branch then stages.......

【问题讨论】:

    标签: jenkins jenkins-pipeline


    【解决方案1】:

    用双引号将您的${params.BRANCH} 括起来,或者只使用BRANCH,它们中的任何一个都应该可以工作。

    如果我签出 master 分支,然后部署到某个 S3 位置,否则如果 dev 分支到某个其他位置

    pipeline {
        agent any
        parameters {
            choice(
                name: 'BRANCH',
                choices: 'Development\nrelease/release_QA\nmaster',
                description: 'Selct the branch to deploy to repective Airflow')
        }
        stages {
            stage('checkout code') {
                steps {
                    git(url: 'https://bitbucket.nike.com/scm/something.git', branch: "${params.BRANCH}", credentialsId: '4db2-aec4-7d5e86c4ff4b', changelog: true)
                }   
            }
            stage('Deploy to S3') {
                when {
                    expression {
                        BRANCH == 'master'
                    }
                }
                // Deploy to S3
            }
            stage('Deploy elsewhere') {
                when {
                    expression {
                        BRANCH == 'Development'
                    }
                }
                // Deploy elsewhere
            }
        }
    }
    

    【讨论】:

    • 非常感谢,您能告诉我如何根据分支编写S3部署的逻辑吗,请告诉我如何根据分支选择编写阶段。再次感谢 。 @ben5556
    • 根据所选分支更新了我的运行阶段答案。请刷新页面。
    • 非常感谢,这是我第一次体验 stackoverflow 我爱你的支持非常感谢:-) @ben5556
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多