I am using docker containers as Jenkins build agents. All build agents, jenkins master node are docker containers running on same host. (no different vms)
Following is the Docker Agent template I am using to build an angular app.
- These are Docker Agents with sshds. Public keys are injected using env variables.
- The build Agent docker image has npm and angular-cli installed.
Jenkins File is as follows. I can not change Jenkins file. So the above build agent has been labeled as node in jenkinsfile.
pipeline {
agent {
node {
label 'ng6'
}
}
stages {
stage('build && SonarQube analysis') {
steps {
withSonarQubeEnv('XX SonarQube') {
sh '''
npm install
ts-node git.version.ts
ng build --prod
(cd dist ; tar -czf ../xx-ng.tar.gz.)
'''
}
archiveArtifacts(artifacts: 'xx-ng.tar.gz', fingerprint: true)
}
}
- Build runs successfully. I am able to get artifacts
What I am doing I will mount .npm and node_modules in the docker template configuration. (-v)
What I want
Faster build. I want to persist this workspace directory using docker volume mount option
/home/jenkins/workspace/xx-ng_master-ZWS24TQFDFQRGZ3QMEVULORQISDY3BPEWLM7KFGJ42I33NOQFULA
So that node_modules should be persistent and build will be faster. How can I get that directory path and put it in the docker agent template?
<Path_to_workspace>/<Path_build>