Last active
February 21, 2020 21:38
-
-
Save katcaola/2f18350ee66e0a3b2feb57a2992643c3 to your computer and use it in GitHub Desktop.
Title says it all
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
// 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