- [Instructor] Now that we have two load balancers,
one for running our production code,
and another for testing our code,
let's go ahead and give Jenkins the smarts
to first deploy something on testing,
make sure it actually works,
and then, let the pipeline continue through
to deploying it into production.
So heading back to the editor
and into our deployment pipeline,
here we have the stage we just added
that deploys to production at the end of the pipeline.
But we want to add some testing just before that.
So before we deploy it, we'll see if it works.
So we've got this chunk here
which we're going to go ahead and uncomment
and take a look at.
This says let's do some integration testing.
Again, we put the condition on here
that it only happens if we're deploying the master branch,
and then we're going to use the same deployer
we built for the last stage
completely unchanged to deploy here instead.
Check to see that it actually works
by running this script below
and then let the pipeline continue on to production.
So, the next thing we need to do
is put the ARN for the listener
for our testing load balancer right here.
This is the one we just finished building.
So, let's head back to the AWS console.
This is where I want it to land.
Click on the testing website application load balancer
we just built,
and again, right here under the listener's tab
we don't want this part here,
we want this tiny little gray arrow,
which reveals the actual value that we copy
and paste into our Jenkins file.
So now, we've put that there,
one more thing to set.
We need to tell Jenkins where to go look for this code
in order to test it.
We're going to head back to the load balancer.
This time, under the description tab,
grab the DNS name,
make sure that it's the testing one,
copy that and paste it in here.
So, let's take a brief moment
to look at what this script does.
This is a super basic integration test.
It says we're going to use curl,
which is a command line program for fetching things
from the web,
download the contents of the homepage,
run it through grep, which just checks for strings,
and if it has this string on the homepage,
we're going to call it good.
This is very basic.
In a real environment, you'll definitely want something
more sophisticated.
Then, it's going to take the result of that command
and use the shell expression to say,
"If the previous command returned the value zero,"
which is shell for success.
Then, it's going to say, "The tests pass," and do nothing,
doing nothing is equivalent to success.
But if that command doesn't find that string,
the curl command will return something other than zero,
and then the if statement will follow through
to the else block, tell us that it failed,
and it will exit one,
that means make this shell fail.
And if this shell fails,
then the stage that it was running in fails,
and if any stage of a pipeline fails,
the whole thing comes to a stop.
One little note here is that this
leaves the testing environment
in the state it was in when it failed.
This has an up and a down.
You can go look at it and say, "Oh, what went wrong?
"Oh, this thing broke, let's go fix it."
The downside is, it can leave it in a failed state
where it's pretty broken and then the next run
can be kind of messed up by that,
so this goes both ways.
A more sophisticated environment
would do the tests, save a report,
and then clean up afterwards
and also make sure that it cleans up
before it runs.
This has been edited to be a good bite-sized chunk
for learning.
So, let's go ahead and see if this works.
I'm going to save,
check the script,
head on over to the terminal,
and add the Jenkins file to the next git command.
Then, git commit -m for the message,
adding integration test.
Okay, git push origin master.
Okay, let's see if Jenkins goes.
I'm over here in the example web app,
again on the master branch.
I'm going to wait a moment for Jenkins to notice
the new commit.
All right, the deployment went through,
pushed it to a test environment,
checked that it worked,
deployed it to production.
Let's go see if it still works in production.
Here we are at the production website.
Grab the DNS,
open a new tab,
and it works.