Created
November 25, 2020 06:07
-
-
Save pwillis-els/500dc0e51f2988ac46888c9f3a8321c9 to your computer and use it in GitHub Desktop.
Supply Git username/password via environment variables, plus sample Jenkinsfile
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
#!/bin/sh | |
[ "${DEBUG:-0}" = "1" ] && set -x | |
SCRIPT="$0" | |
command -v readlink 2>/dev/null 1>/dev/null && SCRIPT="$(readlink -f "$0")" | |
if [ "$1" = "--install" ] ; then | |
git config --global credential.helper "/bin/sh $SCRIPT" | |
exit $? | |
fi | |
printf "username=%s\n" "$GIT_USERNAME" | |
printf "password=%s\n" "$GIT_PASSWORD" |
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
node('node-label') { | |
stage('Checkout') { | |
scm checkout | |
} | |
stage('Tag') { | |
sh 'git tag my-tag' | |
sh 'sh git-credential-env.sh --install' | |
withCredentials([[ | |
$class: 'UsernamePasswordMultiBinding', | |
credentialsId: 'my-git-credential-id', | |
usernameVariable: 'GIT_USERNAME', | |
passwordVariable: 'GIT_PASSWORD' | |
]]) { | |
sh 'git push origin my-tag' | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment