I have a declarative Jenkins pipeline that looks like the following:
pipeline{
agent {
...
}
stages {
stage("Provision EC2 Instance and Set ENV Variable"){
steps {
dir("docker-image-builder"){
sh 'python ./provisonInstance.py'
}
}
}
stage("Configure EC2 Instance with Ansible"){
steps {
ansiblePlaybook('./ansible.playbook.yml') {
ansibleName('1.9.4')
}
}
}
}
}
In my first stage, I have a Python script that provisions an Amazon EC2 instance that will be used to create an AMI. In the second stage, I will then configure configure my instance before finally creating an AMI and terminating the instance. In order to do this, I need the instance-id of the EC2 instance created in the first stage. Is there an elegant way to pass values generated by a script between stages, and if so how?
The most obvious method that I can think of is to write the value to a file on the agent in the first stage, and read it in the second stage, but this does not seem like an elegant solution.