Access a Jenkins instance with shared libraries for pipelines

We were quite attached to the use of some plugins that are no longer supported in pipelines, and would like to implement their use in the shared libraries of our pipelines. One of the basic elements needed for this is to get a copy of Jenkins, can anyone share this way?

  • Are there any restrictions or the correct way to get Jenkins.getActiveInstance()in the "src" or "vars" folder?

I tried to get Jenkins.getActiveInstance()src code as well as vars code, but it returns null, am I missing something? Any help would be appreciated.

thank

+4
source share
2 answers

Try "Hudson.instance". This pipe below works for me on Jenkins 2.32.x. You may need to execute several script statements or disable the sandbox.

pipeline {

    agent none

    stages{

        stage('Instance Info') {

            steps {
                script {

                    def jenkinsInstance = Hudson.instance

                    for (slave in jenkinsInstance.slaves) {

                        echo "Slave: ${slave.computer.name}"
                    }
                }
            }
        }
    }
}

Bill

+2
source

This ticket can be closed, there were several questions: 1. Fix the access through (Jenkins permission management → In script) 2. Some scripts contain Non-cps code

0
source

Source: https://habr.com/ru/post/1670982/


All Articles