I am using jenkins to execute pipeline, during deployment a status file is generated, I want to save the status file in Jenkins and use it the next time I execute the pipeline.
Question 1: How do I save the status file?
Question 2: When I execute the
post {
always {
cleanWs()
}
}
After that, is the status file still there?
Question 3: The Copy Artifact plugin seems to do something like this, by writing in the pipeline:
archiveArtifacts(
artifacts: 'xxx.xxx',
onlyIfSuccessful: true
)
I’m wondering where in the jenkins directory it will save the state file?
-
There are multiple ways to save a file in Jenkins. If the content you want to save is in a variable then
writeFile
step is your best option. If content of the file is the output of some command try redirecting it to a file in your shell of choice. In bash it would beecho "Success" > status.txt
-
cleanWs
will delete the file. Kind of the whole point of the step – to get rid of the state -
archiveArtifacts
andcopyArtifacts
step are probably the most conventional ways of preserving whatever files you want to keep and accessing them later. Depending on how big your state is you might jam small strings intocurrentBuild.description
and access it later ascurrentBuild.previousBuild.description