2022-10-10 11:56:55 +02:00
|
|
|
import org.jenkinsci.plugins.pipeline.modeldefinition.Utils
|
|
|
|
|
|
|
|
void when(Boolean condition, body) {
|
|
|
|
Map config = [:]
|
|
|
|
body.resolveStrategy = Closure.OWNER_FIRST
|
|
|
|
body.delegate = config
|
|
|
|
|
|
|
|
if (condition) {
|
|
|
|
body()
|
|
|
|
} else {
|
|
|
|
Utils.markStageSkippedForConditional(STAGE_NAME)
|
|
|
|
}
|
2022-12-01 19:38:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonCPS
|
|
|
|
String getBuildUser() {
|
|
|
|
def build = currentBuild.rawBuild
|
|
|
|
String buildUser = ''
|
|
|
|
|
|
|
|
// On essaie de récupérer l'utilisateur à l'origine de l'exécution du job
|
|
|
|
try {
|
|
|
|
def cause = build.getCause(hudson.model.Cause.UserIdCause.class)
|
|
|
|
buildUser = cause.getUserName()
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// On ignore l'erreur
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buildUser == '') {
|
|
|
|
// Si on a pas réussi à retrouver l'utilisateur, on récupère celui du commit courant
|
|
|
|
try {
|
|
|
|
def committerUsername = sh(script: 'git --no-pager show -s --format=\'%ae\' | cut -d\'@\' -f1', returnStdout: true).trim()
|
|
|
|
buildUser = committerUsername
|
|
|
|
} catch (Exception ex) {
|
|
|
|
// On ignore l'erreur
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buildUser == '') {
|
|
|
|
// Par défaut, on considère que jenkins est à l'origine du job
|
|
|
|
buildUser = 'jenkins'
|
|
|
|
}
|
|
|
|
|
|
|
|
return buildUser
|
|
|
|
}
|