Part 4: Jenkins Pipeline
Now for the grand finale, the Jenkins Pipeline.
For the jenkins piece, we will be running jenkins locally and pulling from Git. So push it all up there now.
Fire up jenkins and log in.
Create a new job and select "Pipeline" (call it something intuitive)
Now, I have a Jenkinsfile in my repo that is arbitrary. I keep it there to show off, as well as make edits easily when I need to. We are ultimately going to past it into Jenkins, so its up to you if you want to include it or not.
Take a moment to review it. Note the following:
- It has params at the top
- it checks my repo using Jenkins credentials that I supplied in my instance. These are SSH credentials (private key is in jenkins, public key is in Github). I have covered this in other videos.
- The Terraform stage has an if/else statement for apply or destroy
- Ansible has a retry block in case the connection doesn't work on first try (to avoid the error penalty). Also, note that it uses the -i to reference our Dynamic inventory.
Jenkinsfile
Scroll down to the bottom where it says "Pipeline" and paste in the Jenkinsfile script. Save it and reload.
Try Building it with parameters and see how it goes!
You should be able to see each stage complete:
When you are done standing it up you can navigate to your EC2 url and verify it works.
You should see the ssl warning when using https
You can verify your SSL info as well by clicking the "Not Secure" at the top left.
Click through it and see your static site:
When you are done, You can head back to Jenkins, select "Destroy" and run it! Your verify your instance is terminated and run it for them as many times as they want!
Comments
Post a Comment