Q:

Jenkins pipeline script error WorkflowScript: Expected a step

I have created a testcase from a much bigger Jenkins pipeline project and it works fine.  
pipeline { 
            agent none
        stages {     
            stage ("Check Parameters")
                          { 
                             steps {
                                     echo "In pipeline"
                                     script {
                                           echo "Start condition check"
                                                }
                                     build job: 'printuser'
                                     //def slaveJob = build job: 'printuser'
                                     //println slaveJob.rawBuild.log  
                                        }
                            }
                    }
            }

Howevr, inorder to get the output of printuser job onto the pipeline i comment build job: 'printuser' and uncomment the slaveJob code as below:
                                 //build job: 'printuser'
                                 def slaveJob = build job: 'printuser'
                                 println slaveJob.rawBuild.log  

It now fails with the below error:
org.codehaus.groovy.control. MultipleCompilationErrorsException: startup failed:
WorkflowScript: 13: Expected a step @ line 13, column 15. 
                                            def slaveJob = build job: 'printuser'
                 ^

1 error

    at org.codehaus.groovy.control. ErrorCollector.failIfErrors(ErrorCollector.java:310)
    at org.codehaus.groovy.control. CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
    at org.codehaus.groovy.control. CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
    at org.codehaus.groovy.control. CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
    at org.codehaus.groovy.control. CompilationUnit.compile(CompilationUnit.java:558)
    at groovy.lang. GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
    at groovy.lang. GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
    at groovy.lang. GroovyShell.parseClass(GroovyShell.java:688)
    at groovy.lang. GroovyShell.parse(GroovyShell.java:700)
    at org.jenkinsci.plugins.workflow.cps. CpsGroovyShell.doParse(CpsGroovyShell.java:133)
    at org.jenkinsci.plugins.workflow.cps. CpsGroovyShell.reparse(CpsGroovyShell.java:126)
    at org.jenkinsci.plugins.workflow.cps. CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
    at org.jenkinsci.plugins.workflow.cps. CpsFlowExecution.start(CpsFlowExecution.java:522)
    at org.jenkinsci.plugins.workflow.job. WorkflowRun.run(WorkflowRun.java:320)
    at hudson.model. ResourceController.execute(ResourceController.java:97)
    at hudson.model. Executor.run(Executor.java:429)
Finished: FAILURE

Can you please suggest what is the issue here ? 

A:

If you want to use groovy, you must put it inside the script section, not outside:
script {
    echo "Start condition check"
    build job: 'printuser'
    def slaveJob = build job: 'printuser'
    println slaveJob.rawBuild.log  
}

PS: not sure your code will work as such, but you should at least put it inside the script part.  Outside of the script closure, jenkins will only accept a set of predefined steps.