首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >多个并行阶段,jenkins在每个阶段检查源。

多个并行阶段,jenkins在每个阶段检查源。
EN

Stack Overflow用户
提问于 2020-08-26 07:55:07
回答 1查看 365关注 0票数 0

我不确定这是Jenkins的默认行为。

我有三个并行阶段,每个阶段都假设在前一个阶段生成的文件存在于目录中。

我运行yarn install阶段1yarn build阶段2和在阶段3我有yarn package

每个阶段都试图检查源和抱怨,例如,第2阶段抱怨node_modules不存在,当我检查我在第1阶段工作空间被重置后发现。

是否有方法在阶段完成后将目录/文件保留在工作区中?

任何帮助都是非常感谢的。

编辑1

代码语言:javascript
运行
复制
pipeline {
    agent none

    options {
        skipDefaultCheckout true
    }

    environment {
        BRANCH_NAME = 'mater'
    }

    stages {

        stage ('Checkout source') {
            agent any
            steps {
                checkout([
                    $class: 'GitSCM',
                    branches: [[name: "${env.BRANCH_NAME}"]],
                    doGenerateSubmoduleConfigurations: false,
                    extensions: [],
                    submoduleCfg: [],
                    userRemoteConfigs: [[
                        credentialsId: '5db9bedc-fa88-4f64-9e6a-3e9a9d5c999f',
                        url: 'git@gitserver.io:acme/acme-repo.git'
                    ]]
                ])
            }
        }

        stage ('Test') {
            parallel {
                stage ('[Test] Mac') {
                    agent {
                        node {
                            label 'iMac'
                            customWorkspace "/Users/acme/workspace/acme-repo/nightly/${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        sh 'npm install yarn -g'
                        sh 'yarn install --network-timeout 1000000'
                        sh 'yarn build'
                        sh 'yarn test -u'
                    }
                }

                stage ('[Test] Linux') {
                    agent {
                        node {
                            label 'master'
                            customWorkspace "/var/lib/jenkins/acme/acme-repo/nightly/${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        sh 'sudo npm install yarn -g'
                        sh 'yarn install --network-timeout 1000000'
                        sh 'yarn build'
                        sh 'yarn test -u'                        
                    }
                }

                stage ('[Test] Windows') {
                    agent {
                        node {
                            label 'win'
                            customWorkspace "E:\\jenkins_agent\\acme\\nightly\\${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        bat 'npm install yarn -g'
                        bat 'yarn install --network-timeout 1000000'
                        bat 'yarn build'
                        bat 'yarn test -u'                        
                    }
                }                                    
            }
        }


        stage ('Package') {
            parallel {
                stage ('Mac') {
                    agent {
                        node {
                            label 'iMac'
                            customWorkspace "/Users/acme/workspace/acme-repo/nightly/${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        sh 'yarn package-mac'
                    }
                }

                stage ('Linux') {
                    agent {
                        node {
                            label 'master'
                            customWorkspace "/var/lib/jenkins/acme/acme-repo/nightly/${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        sh './node_modules/.bin/yarn package-linux'
                    }
                }

                stage ('Windows') {
                    agent {
                        node {
                            label 'win'
                            customWorkspace "E:\\jenkins_agent\\acme\\nightly\\${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        bat 'yarn package-win'
                    }
                }                                    
            }
        }

        stage ('Publish') {
            parallel {
                stage ('[Publish] Mac') {
                    agent {
                        node {
                            label 'iMac'
                            customWorkspace "/Users/acme/workspace/acme-repo/nightly/${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        sh 'yarn publish-mac'
                    }
                }

                stage ('[Publish] Linux') {
                    agent {
                        node {
                            label 'master'
                            customWorkspace "/var/lib/jenkins/acme/acme-repo/nightly/${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        sh './node_modules/.bin/yarn publish-linux'
                    }
                }

                stage ('[Publish] Windows') {
                    agent {
                        node {
                            label 'win'
                            customWorkspace "E:\\jenkins_agent\\acme\\nightly\\${env.BRANCH_NAME}"
                        }
                    }
                    steps {
                        bat 'yarn publish-win'
                    }
                }                                    
            }
        }        

        stage ('Tag & Push') {
            agent {
                node {
                    label 'master'
                    customWorkspace "/var/lib/jenkins/acme/acme-repo/nightly/${env.BRANCH_NAME}"
                }
            }
            steps {
                sh "yarn version --patch"
                sh 'git push git@gitserver.io:acme/acme-repo.git HEAD:$BRANCH_NAME'
            }
        }
    }
}

为了给出更多的细节-有

(parallel)

  • package (parallel)

  • publish (并行)
  1. 签出源
  2. 测试

每个阶段都是针对不同的环境定义的。问题是在运行package阶段时,显然,工作区被清理了,所以没有什么可运行的包。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-29 06:55:48

事实证明,我需要用-

代码语言:javascript
运行
复制
    options {
        // This is key setting that enables one checkout across different stages
        skipDefaultCheckout true
    } 

若要跳过默认结帐,请执行以下操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63593032

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档