Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save katcaola/2f18350ee66e0a3b2feb57a2992643c3 to your computer and use it in GitHub Desktop.
Save katcaola/2f18350ee66e0a3b2feb57a2992643c3 to your computer and use it in GitHub Desktop.
Title says it all
// This was failing my build:
archiveArtifacts artifacts: '**/${env.DOCKER_FILE_NAME}', fingerprint: false
// SHOULD BE THIS
archiveArtifacts artifacts: "**/${env.DOCKER_FILE_NAME}", fingerprint: false
------------------------------------------------------------------------------------------------------------
// If you need vars that are global and changeable, you need them outside of the pipeline
VAR="value"
pipeline {
...
}
// Env vars are only changeable temporarily with a "with env" block
pipeline {
environment {
VAR="VALUE"
}
stage {
steps {
VAR = "NEW VALUE" // won't work
withEnv(['VAR="NEW NEW VALUE"']){
... // VAR will only be "NEW NEW VALUE" in this block. That's it.
// Not helpful for setting a global to be used later
}
}
}
}
------------------------------------------------------------------------------------------------------------
// I couldn't find another way to set variables in a script{} block
// DIDN'T WORK
EMAIL_TEXT = "Build is BACK TO NORMAL"
// worked (╯°□°)╯︵ ┻━┻)
EMAIL_TEXT = sh([script: "echo 'Build is BACK TO NORMAL'", returnStdout: true]).trim()
------------------------------------------------------------------------------------------------------------
// Declarative pipelines hate if else statements that expand vars.
// didn't work
if ("${CURRENT_BUILD}" == "UNSTABLE"){...}
// didn't work
if (${CURRENT_BUILD} == "UNSTABLE"){...}
--> java.lang.NoSuchMethodError: No such DSL method '$' found among steps
// didn't work
if (CURRENT_BUILD == "UNSTABLE"){...}
// didn't work
if (CURRENT_BUILD == 'UNSTABLE'){...}
// didn't work
if ("${CURRENT_BUILD}" == "UNSTABLE")
...
// worked (╯°□°)╯︵ ┻━┻)
if (true) {...}
// I added all my logic into a shell script and put the variables as params
------------------------------------------------------------------------------------------------------------
// Post build stuff doesn't like having it's own environment
post {
environment {
TESTS_PASSED = -1 // This failed my build and threw an exception
TESTS_FAILED = -1
TESTS_SKIPPED = -1
TESTS_TOTAL = -1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment