Skip to content

Instantly share code, notes, and snippets.

@pwillis-els
Created November 25, 2020 06:07
Show Gist options
  • Save pwillis-els/500dc0e51f2988ac46888c9f3a8321c9 to your computer and use it in GitHub Desktop.
Save pwillis-els/500dc0e51f2988ac46888c9f3a8321c9 to your computer and use it in GitHub Desktop.
Supply Git username/password via environment variables, plus sample Jenkinsfile
#!/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"
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