diff --git a/helpers.groovy b/helpers.groovy index 17503b0..291d0de 100644 --- a/helpers.groovy +++ b/helpers.groovy @@ -44,6 +44,29 @@ def withGiteaCreds(String credentialsId, String gitToolName, Closure body) { gitToolName: gitToolName ) ]) { + sh "git config user.name ${env.GIT_USERNAME}" + sh "git config user.email admin@dipal.ru" + body() + } +} +/* -------------------------------------------------------------------------- */ +/** +* Wrapper function for `withCredentials` and `docker login` command. +* +* By passing existing `credentialsId` and link to `registry` will be +* extracted credentials from Jenkins and try to login to the registry +* using them. After all will be executed provided closure. +* +*/ +def withDockerCreds(String credentialsId, String registry, Closure body) { + withCredentials([ + usernamePassword( + credentialsId: credentialsId, + usernameVariable: "DOCKER_LOGIN", + passwordVariable: "DOCKER_PASSWORD", + ) + ]) { + sh "docker login ${registry} -u ${DOCKER_LOGIN} -p ${DOCKER_PASSWORD}" body() } }