Last active
April 15, 2020 14:11
-
-
Save akostadinov/fc8940fda63a7489492b637063233524 to your computer and use it in GitHub Desktop.
Jenkins Pipeline code Examples
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
// clone in sub-directory | |
checkout([ | |
$class: 'GitSCM', | |
branches: [[name: 'master']], | |
doGenerateSubmoduleConfigurations: false, | |
extensions: [[ | |
$class: 'RelativeTargetDirectory', | |
relativeTargetDir: 'some/path' | |
]], | |
submoduleCfg: [], | |
userRemoteConfigs: [[ | |
credentialsId: 'a9fb86e4-bd29-425f-a834-16efe6009d84', | |
url: 'ssh://[email protected]:22/myproject' | |
]] | |
]) | |
// Get parameter value of an existing build from another job | |
// this fails in sandbox | |
def job = Jenkins.instance.getItemByFullName("My Job") | |
def build = job.getBuildByNumber(buildNum.toInteger()) | |
// println build.getEnvVars().get('CUCUSHIFT_CONFIG', null) | |
paramValue = build.allActions. | |
find {it in hudson.model.ParametersAction}. | |
getParameter("MY_PARAM_NAME"). | |
value | |
// Launch Shell with variables and ascii color highlighting | |
dir('some/path') { | |
withEnv(["MY_ENV_VAR=${multilineString}"]) { | |
ansiColor('gnome-terminal') { | |
sh 'echo "$MY_ENV_VAR"' | |
} | |
} | |
} |
@dyennam, this is a variable you should have defined. It is not a method to get current build number or something. The thing is it needs to be an integer. What variable name you use is not important.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, Just a quick question:
Shouldn't line 20 say buildNumber.toInteger() ?