作者:mobiledu2502925333 | 来源:互联网 | 2023-02-05 15:33
我想从Jenkins Declarative Pipeline设置构建名称和描述,但找不到正确的方法.我尝试在管道之后使用环境支架,在代理程序括号中使用节点括号等.我总是遇到语法错误.
我的Jenkinsfile的最后一个版本是这样的:
pipeline {
stages {
stage("Build") {
steps {
echo "Building application..."
bat "%ANT_HOME%/bin/ant.bat clean compile"
currentBuild.name = "MY_VERSION_NUMBER"
currentBuild.description = "MY_PROJECT MY_VERSION_NUMBER"
}
}
stage("Unit Tests") {
steps {
echo "Testing (JUnit)..."
echo "Testing (pitest)..."
bat "%ANT_HOME%/bin/ant.bat run-unit-tests"
}
}
stage("Functional Test") {
steps {
echo "Selenium..."
}
}
stage("Performance Test") {
steps {
echo "JMeter.."
}
}
stage("Quality Analysis") {
steps {
echo "Running SonarQube..."
bat "%ANT_HOME%/bin/ant.bat run-sonarqube-analysis"
}
}
stage("Security Assessment") {
steps {
echo "ZAP..."
}
}
stage("Approval") {
steps {
echo "Approval by a CS03"
}
}
stage("Deploy") {
steps {
echo "Deploying..."
}
}
}
post {
always {
junit '/test/reports/*.xml'
}
failure {
emailext attachLog: true, body: '', compressLog: true, recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider']], subject: '[JENKINS] MY_PROJECT build failed', to: '...recipients...'
}
success {
emailext attachLog: false, body: '', compressLog: false, recipientProviders: [[$class: 'DevelopersRecipientProvider']], subject: '[JENKINS] MY_PROJECT build succeeded', to: '...recipients...'
}
}
}
错误是:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 11: Expected a step @ line 11, column 5.
currentBuild.name = "MY_VERSION_NUMBER"
^
WorkflowScript: 12: Expected a step @ line 12, column 5.
currentBuild.description = "MY_PROJECT MY_VERSION_NUMBER"
^
理想情况下,我希望能够从build.properties文件或Jenkins构建日志中读取MY_PROJECT和MY_VERSION_NUMBER.关于该要求的任何指导也将受到赞赏.
UPDATE
根据我在下面的答案,以下工作:
stage("Build") {
steps {
echo "Building application..."
bat "%ANT_HOME%/bin/ant.bat clean compile"
script {
def props = readProperties file: 'build.properties'
currentBuild.displayName = "v" + props['application.version']
}
}
现在,通过读取build.properties文件,在管道期间自动设置构建版本.
1> Mateo..:
我想这会做你想要的.我能够在一个script
街区内完成:
pipeline {
stages {
stage("Build"){
steps {
script {
currentBuild.displayName = "The name."
currentBuild.description = "The best description."
}
... do whatever.
}
}
}
}
该脚本是逃离声明性管道的一种逃避方法.可能有一种声明性的方式来做,但我找不到它.还有一点需要注意.我想你想要currentBuild.displayName
而不是currentBuild.name
在Jenkins全局文件的文档中,我没有在currentBuild下看到name属性.
2> Carlos Andre..:
如果要通过参数为作业设置内部版本名称,则可以使用
currentBuild.displayName = "${nameOfYourParameter}"
。
确保使用双引号而不是单引号。
作业配置
使用参数构建作业
建立历史
参考:如何在管道作业中设置内部版本名称?