我需要帮助詹金斯的时间条件。我想从合并请求标题中取出FULL_BUILD字样,然后根据它是FULL_BUILD还是只是向主人提交合并请求而不需要通过Veracode,SonarQube等等来执行不同的阶段(这些阶段没有粘贴,因为它们只是重复下面的条件)。但是,我必须在每个阶段的条件重复这个疯狂,有时创建一个只在FULL_BUILD或"常规"上执行的特殊阶段。建立。
是否有人创建了@NonCPS脚本来设置true / false变量?或者是否有一种在启动时执行脚本以设置可重用变量的狡猾方法?
我想让用户从他们的Gitlab MR执行所有操作,而不必去Jenkins按一个按钮(因此我不使用boolean参数)。
pipeline {
agent {
node {
label 'master'
}
}
parameters{
//I am trying to pull the information for a full build from the Merge Request
}
environment {
//Assume random variables all work fine
}
options {
skipDefaultCheckout()
gitLabConnection('GitLab_Generic')
timeout(time: 60, unit: 'MINUTES')
}
triggers {
gitlab(triggerOnPush: true, triggerOnMergeRequest: true, branchFilterType: 'All')
}
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
dir("${env.WORKSPACE}\\${params.PROJECT_NAME}") {
bat 'nuget.exe restore %PROJECT_NAME%.sln'
}
dir("${env.WORKSPACE}\\${params.PROJECT_NAME}\\build") {
bat "\"${tool 'msbuild'}\" %COMPONENT%.XML /p:Configuration=Debug "
}
dir("${env.WORKSPACE}") {
echo "Creating a Build status file"
writeFile file: "output/MR_Title.txt", text: "BUILD STATUS:"
}
}
}
stage('Check MR FULL_BUILD' ){
when {
branch 'master'
}
steps{
dir("${env.WORKSPACE}") {
//writeFile file: "MR_Title.txt", text: "BUILD STATUS:"
powershell '& "./build/scripts/MergeRequestAPI.ps1" -GIT_CREDENTIALS $env:GIT_API_TOKEN -PROJECT_ID $env:GIT_PROJECT_ID | Out-File output/MR_Title.txt -Encoding utf8"'
}
}
}
stage('Package Snapshot') {
when {
allOf {
branch 'master'
not {
expression {
return readFile('output/MR_Title.txt').contains("FULL BUILD")
}
}
}
}
steps {
dir("${env.WORKSPACE}\\${params.PROJECT_NAME}\\build") {
bat "\"${tool 'msbuild'}\" %COMPONENT%.XML /t:Publish /p:version=${env.SnapshotComponentVersion} "
}
}
}
stage('Package Full Build') {
when {
allOf {
branch 'master'
expression {
return readFile('output/MR_Title.txt').contains("FULL BUILD")
}
}
}
steps {
dir("${env.WORKSPACE}\\${params.PROJECT_NAME}\\build") {
bat "\"${tool 'msbuild'}\" %COMPONENT%.XML /t:Publish /p:version=${env.ComponentVersion} "
}
}
}
}
}