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
|
|
|
|
}
|
2023-08-17 15:43:26 +02:00
|
|
|
|
|
|
|
String getProjectVersionDefaultChannel() {
|
2023-11-16 11:27:10 +01:00
|
|
|
switch (env.BRANCH_NAME) {
|
|
|
|
case 'develop':
|
|
|
|
return 'develop'
|
|
|
|
|
|
|
|
case 'testing':
|
|
|
|
case 'staging':
|
|
|
|
return 'testing'
|
|
|
|
|
|
|
|
case 'stable':
|
|
|
|
case 'master':
|
|
|
|
return 'stable'
|
|
|
|
|
|
|
|
default:
|
|
|
|
return env.BRANCH_NAME.toLowerCase().replaceAll('(_|-| )+', '')
|
|
|
|
}
|
2023-08-17 15:43:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String getProjectVersionShortChannel(String channel) {
|
|
|
|
switch (channel) {
|
|
|
|
case 'develop':
|
|
|
|
return 'dev'
|
2023-11-16 11:27:10 +01:00
|
|
|
|
2023-08-17 15:43:26 +02:00
|
|
|
case 'testing':
|
2023-08-23 23:16:33 +02:00
|
|
|
case 'staging':
|
2023-08-17 15:43:26 +02:00
|
|
|
return 'tst'
|
2023-11-16 11:27:10 +01:00
|
|
|
|
2023-08-17 15:43:26 +02:00
|
|
|
case 'stable':
|
2023-08-23 23:16:33 +02:00
|
|
|
case 'master':
|
2023-08-17 15:43:26 +02:00
|
|
|
return 'stb'
|
2023-11-16 11:27:10 +01:00
|
|
|
|
2023-08-17 15:43:26 +02:00
|
|
|
default:
|
|
|
|
return channel.toLowerCase().replaceAll('(a|e|i|o|u|y_|-| )+', '').take(3)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<String> getProjectVersionTags(String overrideChannel = '') {
|
|
|
|
String channel = overrideChannel ? overrideChannel : getProjectVersionDefaultChannel()
|
|
|
|
String shortChannel = getProjectVersionShortChannel(channel)
|
|
|
|
|
2023-08-24 16:42:27 +02:00
|
|
|
String currrentCommitDate = sh(script: 'git show -s --format=%ct', returnStdout: true).trim()
|
2023-08-24 15:51:05 +02:00
|
|
|
String dateVersion = sh(script: "TZ=Europe/Paris date -d '@${currrentCommitDate}' +%Y.%-m.%-d", returnStdout: true).trim()
|
|
|
|
String timestamp = sh(script: "TZ=Europe/Paris date -d '@${currrentCommitDate}' +%-H%M", returnStdout: true).trim()
|
2023-08-17 15:43:26 +02:00
|
|
|
String shortCommit = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
|
|
|
|
|
|
|
|
String longTag = "${dateVersion}-${channel}.${timestamp}.${shortCommit}"
|
|
|
|
String shortTag = "${dateVersion}-${shortChannel}.${timestamp}"
|
|
|
|
|
|
|
|
return [ longTag, shortTag ]
|
|
|
|
}
|
|
|
|
|
|
|
|
Boolean isPR() {
|
|
|
|
return env.BRANCH_NAME ==~ /^PR-.*$/
|
|
|
|
}
|