Jenkins does not accept variable declaration

Viewed 12904

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 {

2 Answers

In my case, I did declare a variable using the stages name: def stages = [buildStage]

Changing this variable name to another name fixed my issue.

Related