Jenkins宣言型パイプラインからビルド名と説明を設定したいが、適切な方法が見つからない。私はパイプラインの後に、環境変数を使ってみました。エージェントブラケットなどのノードブラケットを使っていました。私はいつも構文エラーが出ます。Jenkins宣言型パイプラインからビルド名と説明を設定します
私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からMY_PROJECTとMY_VERSION_NUMBERを読むことができるようにしたいのですがファイル、またはJenkinsビルドログから取得できます。その要件に関するガイダンスも高く評価されます。
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ファイルを読み出すことにより、パイプラインの間に設定されています。
作品不思議。ありがとうございました! –