【问题标题】:Jenkinsfile in repo different from the code仓库中的 Jenkinsfile 与代码不同
【发布时间】:2019-06-20 05:18:04
【问题描述】:

目标:为所有 jenkins 工作(大约 100 个)拥有一个 Jenkinsfile -“一个文件来统治所有工作”

我尝试过的:

使用 2 个 repo 创建一个 jenkins 作业:

1 - {GIT_URL_1} : Jenkinsfile 的仓库在哪里

2 - {GIT_URL_2}:包含要​​构建的代码的仓库

詹金斯文件

stage('Checkout'){
        when {
            not {
                anyOf {
                    branch 'master';
                    branch 'develop';
                    branch 'release'
                }
            }

        }
        steps { 
            // dir ('repo') {
                updateGitlabCommitStatus name: 'build', state: 'running'                                
                git "${GIT_URL_1}"
                checkout changelog: true, poll: true, scm: [
                $class: 'GitSCM',
                branches: [[name: "${gitlabSourceBranch}"]],
                doGenerateSubmoduleConfigurations: false
                load 'Jenkinsfile'
            } 

错误信息

错误:/var/lib/jenkins/workspace/app/myapp@script/Jenkinsfile 不是 找到了

如果我交换 GIT_URL 位置 - 先签出 repo,然后签出 jenkinsfile,我会收到相同的错误消息

【问题讨论】:

标签: gitlab jenkins-pipeline


【解决方案1】:

我通过在签出第二个 repo 之前更改目录解决了这个问题。

steps { 
                updateGitlabCommitStatus name: 'jenkins', state: 'running'
                dir ('repo') {                    
                git branch: "${gitlabSourceBranch}", credentialsId: 'ABCDEFG', url: "${gitlabSourceRepoURL}"  

1 - 使用 jenkinsfile 签出 repo

2 - jenkinfile 更改目录

3 - 使用要构建的代码检查 repo

此解决方案会导致其他小问题,例如来自错误存储库(jenkinsfile 存储库)的更改日志,但我可以处理它。

也比创建共享库更快(这是更好的解决方案)

【讨论】:

    猜你喜欢
    • 2019-03-22
    • 2019-07-21
    • 2021-06-20
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多