Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting unknown type : import in groovy in Jenkins Pipeline

I am trying to create a Jenkins Pipeline Script using groovy. However, the import statement is giving me a compilation error - Unknown Type : Import. Not sure why.

Screenshot attached here

like image 515
Bipin Avatar asked Jun 11 '18 07:06

Bipin


1 Answers

You should define import jxl.* at the top of the pipeline script, e.g.

import jxl.*

node {
    stage('Execute Tests') {
        try {
           dir('.') {
               sh '......' // etc.
           }
        }
    }
}

When you added it inside node {} block Jenkins was looking for a method instead of import class statement. The good convention is to put all import statements at the top of the Groovy file.

like image 96
Szymon Stepniak Avatar answered Sep 29 '22 01:09

Szymon Stepniak