如何在Jenkins文件中加入两个值?
**我试图通过下面的jenkins文件语法来串联两个值。也许,我无法做到。
输出值 + Jenkins构建编号应保存在新变量**
连接的控制台输出 /日志中以供参考。寻找此问题声明的输入 /建议。
pipeline {
agent any
environment {
AWS_ACCOUNT_ID="xyz"
AWS_DEFAULT_REGION="xyz"
IMAGE_REPO_NAME="abc/xyz"
REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
BLD_NUMBER = "${env.BUILD_NUMBER}"
}
stages {
stage('Logging into AWS ECR') {
steps {
script {
sh "aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
}
}
}
stage('Build Release') {
steps {
script {
def version = sh script: 'mvn help:evaluate -Dexpression=project.version -q -DforceStdout', returnStdout: true
sh "echo version value is $version"
def pom_toupdate = sh script: "echo ${version} | rev | cut -c2- | rev", returnStdout: true
sh "echo pom_toupdate version is $pom_toupdate"
def newpomversion = sh script: "echo ${pom_toupdate} + ${BLD_NUMBER}", returnStdout: true
sh "echo newpomversion value is $newpomversion"
}
}
}
}
output_error / logs:
Login Succeeded
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build Release)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ mvn help:evaluate -Dexpression=project.version -q -DforceStdout
[Pipeline] sh
+ echo version value is 4.51.0
version value is 4.51.0
[Pipeline] sh
+ rev
+ cut -c2-
+ rev
+ echo 4.51.0
[Pipeline] sh
+ echo pom_toupdate version is 4.51.
pom_toupdate version is 4.51.
[Pipeline] sh
+ echo 4.51.
+ 195
/var/lib/jenkins/workspace/xxx@tmp/durable-d0262401/script.sh: line 2: 195: command not found
4.51.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
desired_output:
newpomversion should have 4.51.195
** I am trying to concatenate two values via below Jenkins file syntax. Perhaps, I am unable to do so.
output value + jenkins build number should be saved in a new variable **
Attached console output / logs for reference. Looking for inputs / recommendation for this problem statement.
pipeline {
agent any
environment {
AWS_ACCOUNT_ID="xyz"
AWS_DEFAULT_REGION="xyz"
IMAGE_REPO_NAME="abc/xyz"
REPOSITORY_URI = "${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${IMAGE_REPO_NAME}"
BLD_NUMBER = "${env.BUILD_NUMBER}"
}
stages {
stage('Logging into AWS ECR') {
steps {
script {
sh "aws ecr get-login-password --region ${AWS_DEFAULT_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com"
}
}
}
stage('Build Release') {
steps {
script {
def version = sh script: 'mvn help:evaluate -Dexpression=project.version -q -DforceStdout', returnStdout: true
sh "echo version value is $version"
def pom_toupdate = sh script: "echo ${version} | rev | cut -c2- | rev", returnStdout: true
sh "echo pom_toupdate version is $pom_toupdate"
def newpomversion = sh script: "echo ${pom_toupdate} + ${BLD_NUMBER}", returnStdout: true
sh "echo newpomversion value is $newpomversion"
}
}
}
}
OUTPUT_ERROR / LOGS:
Login Succeeded
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Build Release)
[Pipeline] script
[Pipeline] {
[Pipeline] sh
+ mvn help:evaluate -Dexpression=project.version -q -DforceStdout
[Pipeline] sh
+ echo version value is 4.51.0
version value is 4.51.0
[Pipeline] sh
+ rev
+ cut -c2-
+ rev
+ echo 4.51.0
[Pipeline] sh
+ echo pom_toupdate version is 4.51.
pom_toupdate version is 4.51.
[Pipeline] sh
+ echo 4.51.
+ 195
/var/lib/jenkins/workspace/xxx@tmp/durable-d0262401/script.sh: line 2: 195: command not found
4.51.
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
ERROR: script returned exit code 127
Finished: FAILURE
DESIRED_OUTPUT:
newpomversion should have 4.51.195
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论