Skip to content

Instantly share code, notes, and snippets.

@benpdavison
Created August 2, 2018 08:28
Show Gist options
  • Save benpdavison/1b3dbcf3b4ab42aebe2ae8bb3542f3fb to your computer and use it in GitHub Desktop.
Save benpdavison/1b3dbcf3b4ab42aebe2ae8bb3542f3fb to your computer and use it in GitHub Desktop.
// This code should allow you to update the different fields in the appspec.yml for AWS Code Deploy.
// Updating the source file location is just an example. All paramaters can be edited.
// readYaml and writeYaml come from the pipline-utility-steps-plugin (https://github.com/jenkinsci/pipeline-utility-steps-plugin)
void updateAppspec(String newFile) {
// By default reads from the working directory
String appspecFile = "appspec.yml"
Map data = readYaml file: appspecFile
String destination = data.files[0].destination
// files is a ArrayList
data.files.set(0, ["source":newFile, "destination": "${destination}"])
// Reove appspec file before writing otherwise it will not work.
sh "rm -f ${appspecFile}"
writeYaml file: appspecFile, data: data
// verify value has been updated
Map newYml = readYaml file: appspecFile
assert newYml.files[0].source == newFile
}
def call(Map config) {
// declerative pipeline
pipeline {
agent any
stages {
stage('Update appspec'){
steps{
updateAppspec('newSourceFile')
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment