Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Forked from JohnnyChiang/Jenkinsfile
Created June 7, 2021 05:22
Show Gist options
  • Save bogdanRada/0c91ff416cbf4dfb24369c3c4b2479c3 to your computer and use it in GitHub Desktop.
Save bogdanRada/0c91ff416cbf4dfb24369c3c4b2479c3 to your computer and use it in GitHub Desktop.
Extract parameters from a jenkins previous build (Declarative pipeline example)
#!groovy
pipeline {
agent any
parameters {
string(name: 'CAUSE', defaultValue: 'anonymous', description: 'Build Cause')
}
stages {
stage('Test Previous Build Status') {
steps {
script {
def lastSuccessfulBuildParams = Jenkins.instance.getItem("${env.JOB_NAME}").lastSuccessfulBuild.actions.find{ it instanceof ParametersAction }?.parameters.find{it.name == 'CAUSE'}?.value
echo "${lastSuccessfulBuildParams}"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment