在我的 jenkins 管道中,我正在使用Pipeline Utility Steps插件读取存储在 yaml 文件中的数据
我可以从文件中读取数据,现在我想更新该值并将其写回文件,如下所示:
pipeline {
agent any
stages {
stage('JOb B ....'){
steps{
script{
def datas = readYaml file:"${WORKSPACE}/Version.yml"
echo datas.MAJOR_VERSION //output is 111
datas = ['MAJOR_VERSION': '222']
writeYaml file:"${WORKSPACE}/Version.yml", data: datas
}
}//steps
}//stage
}//stages
}//pipeline
Run Code Online (Sandbox Code Playgroud)
但我收到错误 - Version.yml 已经存在:
java.nio.file.FileAlreadyExistsException: /var/lib/jenkins/workspace/t-cicd-swarm-example_hdxts-job-B/Version.yml already exist.
at org.jenkinsci.plugins.pipeline.utility.steps.conf.WriteYamlStep$Execution.run(WriteYamlStep.java:175)
at org.jenkinsci.plugins.pipeline.utility.steps.conf.WriteYamlStep$Execution.run(WriteYamlStep.java:159)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
Run Code Online (Sandbox Code Playgroud)
看来它只能写入一个新文件,而不能覆盖现有文件。如何从上面显示的脚本更新现有 yaml 文件的内容?
continuous-integration build continuous-deployment jenkins jenkins-pipeline