Issue
In Jenkins declarative pipeline, I have seen following code used to build project in a docker container as build agent.
agent {
docker {
image 'myUbuntuImage:latest'
args '-u root --privileged'
}
}
Can we do the same in scripted pipeline? May be something like this (or is there any alternative?) -
node('myUbuntuImage:latest`){
// your build commands
}
Solution
I found this code which looks simple and clean. It is almost identical to what I expected.
node{
withDockerContainer(args: '-some -arguents', image: 'myUbuntuImage:latest'){
// your build steps
}
}
See the doc here - https://www.jenkins.io/doc/pipeline/steps/docker-workflow/
Answered By - Shubham Patel
Answer Checked By - Willingham (JavaFixing Volunteer)