jenkins-tools/helpers.groovy

50 lines
1.4 KiB
Groovy

/* -------------------------------------------------------------------------- */
/**
*
* 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
)
]) {
body()
}
}
/* -------------------------------------------------------------------------- */