From 9c8cbb9e63734b4d78c51d1c981c5e646409e458 Mon Sep 17 00:00:00 2001 From: weissmall Date: Mon, 4 Dec 2023 13:45:05 +0300 Subject: [PATCH] Added docker creds wrapper and updated git one --- helpers.groovy | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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() } }