Skip to content

Instantly share code, notes, and snippets.

@tdelphi
Last active December 6, 2017 16:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdelphi/e8dbfb4cc6180370354326265dd485ac to your computer and use it in GitHub Desktop.
Save tdelphi/e8dbfb4cc6180370354326265dd485ac to your computer and use it in GitHub Desktop.
Jenkins-howto

Jenkins dsl to create job params

pipeline {
    agent any
    parameters {
        string(name: 'PERSON', defaultValue: 'Mr Jenkins', description: 'Who should I say hello to?')
    }
    stages {
        stage('Example') {
            steps {
                echo "Hello ${params.PERSON}"
            }
        }
    }
}

Jenkins launch another job and get results

pipeline {
    agent any
    stages {
        stage('Stage 1') {
            steps {
                script {
                    def testJob = build 'test job'
                    testJobNumber = testJob.getNumber()
                }
            }
        }
        stage('Stage 2') {
            steps {
                echo "version was built ${testJobNumber}"
            }
        }
    }
}

other results are available

def jobResult = build 'test job'
echo 'jobResult.getNumber()='+jobResult.getNumber()
echo 'jobResult.getResult()='+jobResult.getResult()
echo 'jobResult.getCurrentResult()='+jobResult.getCurrentResult()
echo 'jobResult.getDescription()='+jobResult.getDescription()
echo 'jobResult.getDisplayName()='+jobResult.getDisplayName()
echo 'jobResult.getFullDisplayName()='+jobResult.getFullDisplayName()
echo 'jobResult.getId()='+jobResult.getId()

Output:

Scheduling project: test job
Starting building: test job #11
jobResult.getNumber()=11
jobResult.getResult()=SUCCESS
jobResult.getCurrentResult()=SUCCESS
jobResult.getDescription()=null
jobResult.getDisplayName()=#11
jobResult.getFullDisplayName()=test job #11
jobResult.getId()=11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment