Last active
March 20, 2023 20:48
-
-
Save JohnnyChiang/906b6c42ba8d4d0236f6ca13cd76ace1 to your computer and use it in GitHub Desktop.
Extract parameters from a jenkins previous build (Declarative pipeline example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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
not running it intanceof Parameter causing error