Created
August 2, 2018 08:28
-
-
Save benpdavison/1b3dbcf3b4ab42aebe2ae8bb3542f3fb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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