2020-03-20 17:15:15 +01:00
|
|
|
def withHTTPCredentials(String credentialsId, Closure fn) {
|
|
|
|
withCredentials([
|
|
|
|
usernamePassword(
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
usernameVariable: 'GIT_USERNAME',
|
|
|
|
passwordVariable: 'GIT_PASSWORD'
|
|
|
|
)
|
|
|
|
]) {
|
|
|
|
def randomUUID = UUID.randomUUID().toString()
|
|
|
|
def tmpAskPassScript = pwd(tmp:true) + "/${randomUUID}"
|
|
|
|
try {
|
|
|
|
writeFile(
|
|
|
|
file: tmpAskPassScript,
|
|
|
|
text: '''
|
|
|
|
#!/bin/sh
|
|
|
|
case "$1" in
|
|
|
|
Username*) echo $GIT_USERNAME ;;
|
|
|
|
Password*) echo $GIT_PASSWORD ;;
|
|
|
|
esac
|
|
|
|
'''
|
|
|
|
)
|
|
|
|
sh(script: "chmod +x '${tmpAskPassScript}'")
|
|
|
|
withEnv(["GIT_ASKPASS=${tmpAskPassScript}"]) {
|
|
|
|
fn.call()
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
sh(script: "rm -f '${tmpAskPassScript}'")
|
|
|
|
}
|
|
|
|
}
|
2021-09-09 15:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
def withSSHCredentials(String credentialsId, Closure fn) {
|
|
|
|
def randomUUID = UUID.randomUUID().toString()
|
|
|
|
withCredentials([
|
|
|
|
sshUserPrivateKey(
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
keyFileVariable: 'GIT_SSH_IDENTITY_FILE',
|
|
|
|
)
|
|
|
|
]) {
|
2021-09-14 15:23:16 +02:00
|
|
|
withEnv(['GIT_SSH_VARIANT=ssh', 'GIT_SSH_COMMAND=ssh -i $GIT_SSH_IDENTITY_FILE -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null']) {
|
2021-09-09 15:45:34 +02:00
|
|
|
fn.call()
|
|
|
|
}
|
|
|
|
}
|
2020-03-20 17:15:15 +01:00
|
|
|
}
|