Issue
I am trying to start a docker image from Jenkins. (Not getting Docker to run from within Jenkins) I think I'm really close but this part has still some issues. Can please anyone help?
stage('build Dockerimage 1') {
steps{
apitestimage = docker.build('apitestimage', '--no-cache=true dockerbuild')
}
}
stage('start Dockerimage and Tests 2') {
steps{
apitestimage.inside {
sh 'cd testing && ctest'
}
}
}
Jenkins reports: WorkflowScript: 21: Expected a step @ line 21, column 15. apitestimage = docker.build('apitestimage', '--no-cache=true dockerbuild')
and also
WorkflowScript: 27: Method calls on objects not allowed outside "script" blocks. @ line 27, column 13. apitestimage.inside {
Solution
From your error, it shows that you're missing a script
block in your steps. You'll need a script block when using the DSL in steps
.
stage('build Dockerimage 1') {
steps{
script {
def apitestimage = docker.build('apitestimage', '--no-cache=true dockerbuild')
}
}
}
stage('start Dockerimage and Tests 2') {
steps{
script {
apitestimage.inside {
sh 'cd testing && ctest'
}
}
}
}
References:
Answered By - Oluwafemi Sule