Created
April 11, 2023 10:10
-
-
Save reitzig/abaad3760c8ac2c6bc7f61898da84a7b to your computer and use it in GitHub Desktop.
Jenkins: stash-like helper functions that use artifacts
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
void stashAsArtifact(steps, String name, String fileGlob) { | |
steps.sh([label: "Bundle stash ${name}", | |
script: "#!/usr/bin/env bash\nshopt -s globstar\ntar --hard-dereference -czf '${name}.tar.gz' ${fileGlob}"]) | |
steps.archiveArtifacts([artifacts: "${name}.tar.gz", | |
fingerprint: true, | |
onlyIfSuccessful: true]) | |
} | |
void unstashFromArtifact(steps, String name) { | |
steps.unarchive(mapping: ["${name}.tar.gz": "${name}.tar.gz"]) | |
steps.sh([label: "Unbundle stash ${name}", | |
script: "tar -xzf '${name}.tar.gz' --unlink-first --recursive-unlink && rm '${name}.tar.gz'"]) | |
} |
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
// "Stash" in one stage ... | |
script { | |
stashAsArtifact(this, 'node-dependencies', '**/node_modules/') | |
} | |
// ... and "unstash" in another | |
script { | |
unstashFromArtifact(this, 'node-dependencies') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The official docs say:
In my experiments, this didn't perform better. Probably because I don't avoid the main reason stated:
So it's definitely a better idea to go another route: