Issue
I'm not sure this is default behavior of Jenkins.
I have three parallel stages each assumes files produced in previous stage is present in the directory.
I run yarn install
in stage 1 and yarn build
in stage 2 and in stage 3 I have yarn package
.
Each stage tries to checks out source and complains, for example, stage 2 complains that node_modules
is not present, when I inspected I found after stage 1 workspace was reset.
Is there way to retain the directories/files in workspace after the stage is complete?
Any help is greatly appreciated.
EDIT 1
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: '[email protected]: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 [email protected]:acme/acme-repo.git HEAD:$BRANCH_NAME'
}
}
}
}
Just to give more details - there are
- checkout source
- test (parallel)
- package (parallel)
- publish (parallel)
Each of these stages are defined for different environment. The problem is when running package
stage, evidently, the workspace is cleaned up so there is nothing to run package
Solution
As it turns out, I need to use -
options {
// This is key setting that enables one checkout across different stages
skipDefaultCheckout true
}
to skip default checkout.
Answered By - asyncwait