I have this Jenkinsfile:
#!groovy
pipeline
{
options {
buildDiscarder(logRotator(numToKeepStr: '10'))
}
agent {
label 'docker && new'
}
stages
{
stage('Docker build')
{
when {
branch 'dev'
}
steps
{
sh "echo ${env.BUILD_NUMBER}"
sh "./scripts/push.sh Docker http://xxxxx.xxxx ${env.BUILD_NUMBER} ${env.GIT_BRANCH}"
sh "echo ${env.BUILD_NUMBER}"
sh "echo ${env.GIT_BRANCH}"
}
}
stage("Initialise")
{
agent {
dockerfile {
filename 'Dockerfile'
label 'docker && new'
args '--entrypoint ""'
}
}
steps {
sh "terraform init -input=false"
}
}
stage("WorkspaceDev") {
agent {
dockerfile {
filename 'Dockerfile'
label 'docker && new'
args '--entrypoint ""'
}
}
when {
branch 'dev'
}
steps {
sh "terraform workspace select dev || terraform workspace new dev"
}
}
}
}
It builds a container from my Dockerfile, However when running this job it is creating a new docker container to run the next stage called WorkspaceDev. I need to use a separate agent for the very first stage and then dockerfile agent for all other stages
How can I use the same container built for the Initialise stage?
Problem:
When running this pipeline the "Docker build" stage is executing on the agent itself as expected. It then gets to the "initialisation" stage. This build a new docker container (docker build (my Dockerfile I have specified in the agent section for this stage). This stage completes inside this container. Next it gets to the "WorkspaceDev" stage - this then AGAIN rebuilds the container with docker build.
I want to use the same container built in the "Initialisation" stage