/* -------------------------------------------------------------------------- */ /** * * Helper function that emits `Success` status. * */ def setSuccessCheck(String name, String title) { publishChecks( name: name, title: title, summary: '— Successful', conclusion: "SUCCESS" ) } /* -------------------------------------------------------------------------- */ /** * Replacement for `stage` function for default pipeline. * * Has the same arguments but does side-effects to the stage: * 1. Runs stage with Gitea checks. It will automatically set check status * as running and failed if stage is failed. * * 2. If stage was successful it will emit `Success` state as a check. * */ def stageWithChecks(String name, Closure body) { stage(name) { body() setSuccessCheck(name, name) } } /* -------------------------------------------------------------------------- */ /** * Wrapper function for `withCredentials` and `gitUsernamePassword` tool. * * By passing `credentialsId` and `gitToolName` it will execute next provided * closure with already activated credentials on git commands. * */ def withGiteaCreds(String credentialsId, String gitToolName, Closure body) { withCredentials([ gitUsernamePassword( credentialsId: credentialsId, gitToolName: gitToolName ) ]) { errorMessage = "Unable to set git config" sh "git config user.name ${env.GIT_USERNAME} || echo $errorMessage" sh "git config user.email admin@dipal.ru || echo $errorMessage" 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() } } /* -------------------------------------------------------------------------- */ return this;