Home > Back-end >  groovy script seems to timeout (jenkins)
groovy script seems to timeout (jenkins)

Time:11-02

I've been having some problems with a groovy script;

sh '''
    echo \'Starting script\';
    sleep 5;
    echo \'pwd\';
    sleep 5; 
    pwd;
    sleep 5;
    find / -name jenkins.war -type f;
    sleep 5;
'''

Commands that take longer to execute always cause the pipeline to fail; all commands except find are run successfully. In the logs (browser), a number of files are shown before the pipeline fails with message:

Jenkins build has status: FAILURE. Notifying  Bitbucket with state: FAILED.

The issue is that there is no direct access to the jenkins server (no easy way to check logs).

I'm not sure if I'm going about this the right way but are there any settings that could cause such behavior?

CodePudding user response:

There's a more elegant, more accurate and much more performant way to get Jenkins' version:

    stages {
        stage('Jenkins version') {
            steps {
                print "${Jenkins.getInstance().getVersion()}"
            }
        }
    }

Console Output

...
[Pipeline] stage
[Pipeline] { (Jenkins version)
[Pipeline] echo
2.303.2
...

Note: getInstance() and getVersion() have to be approved by a Jenkins admin.

You could also curl https://JENKINS_URL/about/ and extract the element/line containing <td>org.jenkins-ci.main:jenkins-war:2.303.2</td>.

  • Related