Converting a freestyle job to a Jenkinsfile. Lint cannot validate

Hello there :wave:

I have a freestyle job that works well; it’s a combination of shell commands, gradle commands and gh commands.
As I did not want to loose the history of my modifications, I decided to create a Jenkinsfile on my GitHub repo, and move my freestyle job to a pipeline.
It’s my first pipeline ever, and I can’t get it to be validated with the Jenkins linter.
What I’m doing wrong must be obvious, but not to me unfortunately:

pipeline {
   agent any
   stages {
       stage('Static Analysis') {
           steps {
               echo 'Run the static analysis to the code'
           }
       }
       stage('Compile') {
           steps {
               script {
                   echo 'Compile the source code'
                   chmod +x ./gradlew
                   ./gradlew build
                   ./gradlew :app:bundleDebug :app:bundleRelease
                   ./gradlew tasks --group publishing
               }
           }
       }
       stage('Security Check') {
           steps {
               echo 'Run the security check against the application'
           }
       }
       stage('Run Unit Tests') {
           steps {
               echo 'Run unit tests from the source code'
           }
       }
       stage('Run Integration Tests') {
           steps {
               echo 'Run only crucial integration tests from the source code'
           }
       }
       stage('Publish Artifacts') {
           steps {
               echo 'Save the assemblies generated from the compilation'
           }
       }
   }
}

The linter says:

WorkflowScript: 14: expecting '}', found 'gradlew' @ line 14, column 23.

Can anyone spot what I’ve done wrong?

Thanks.

I changed my steps to:

 stage('Compile') {
            steps {
                script {
                    sh 'echo "Compile the source code"'
                    sh 'chmod +x ./gradlew'
                    sh './gradlew build'
                    sh './gradlew :app:bundleDebug :app:bundleRelease'
                    sh './gradlew tasks --group publishing'
                }
            }
        }

and it now works. I’m still wondering why echo does work without prefixing it by sh but the other commands have to be prefixed with sh :thinking:

Echo is a Pipeline step, while gradlew is a shell command. The echo Pipeline step has the same name as an echo shell command (and thus can be confusing). The echo Pipeline step is executed inside the Jenkins controller, without starting a shell subprocess.

1 Like

Thanks a lot Mark, now I get why I got confused. :pray:
My bad, I should have better read the existing documentation. :blush:

1 Like