Last active
February 5, 2020 13:08
-
-
Save filviu/a191ebfee006957bef9c1275bd352e18 to your computer and use it in GitHub Desktop.
Jenkins snippets
This file contains hidden or 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
# checkout a repository with branch fallback | |
repos.split(',').each { | |
echo "Checking out ${it}" | |
dir("${it}"){ | |
checkout resolveScm( | |
source: [ | |
$class: 'GitSCMSource', | |
credentialsId: '51234-5678-9101-2131', | |
id: '_', | |
remote: "[email protected]:somebody/${it}.git", | |
traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]], | |
targets: ["${params.BLD_BRANCH}", "${params.FALL_BLD_BRANCH}"] | |
) | |
echo "========== DONE ==========" | |
} | |
} |
This file contains hidden or 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
// requires python but no approval | |
String port = sh(script: 'echo $(python -c \'import socket; s=socket.socket(); s.bind(("", 0)); print(s.getsockname()[1]); s.close()\');', returnStdout: true) | |
// requires approval, looks better | |
// actually doesn't work | |
// https://issues.jenkins-ci.org/browse/JENKINS-56330 | |
def port = new ServerSocket(0).withCloseable { socket -> socket.getLocalPort() } | |
This file contains hidden or 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
# loop through a variable and checkout each repository in it's own folder | |
repos.split(',').each { | |
echo "Checking out ${it}" | |
dir("${it}"){ | |
checkout([ | |
$class: 'GitSCM', | |
branches: [[name: "*/${params.BLD_BRANCH}"]], | |
doGenerateSubmoduleConfigurations: false, | |
extensions: [[$class: 'CleanCheckout']], | |
submoduleCfg: [], | |
userRemoteConfigs: [[credentialsId: '1234-5678-9101-2131', url: "[email protected]:somebody/${it}.git"]] | |
]) | |
echo "========== DONE ==========" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment