Chris Blackden: Hello, and welcome to a beginners tutorial
to Jenkins for IT operations teams. So to start off, think
of Jenkins like a script orchestrator, it looks for an
event, and then it will trigger a script and control the
build environment that that script runs in. So that'll make
more sense in a minute as we go along. To start, let's go to
Manage Jenkins and then scroll down to manage plugins. As a
general rule of thumb, if you ever need Jenkins to integrate
your work with anything, there's a plugin for that. And
let's go here to the available plugins. And I have one
specifically in mind, but it's worth looking through these
to see what it can actually work with. This demo I'm going
to install the file system trigger plugin which will allow
Jenkins to watch a folder for changes and then start a job
or a project based on those changes. So let's go ahead and
install that now. All right, now that that's installed, we
can go back to our Jenkins main page. You see, I've already
got a job here, and we will get to that in a minute. Let's
go to new items so we can create our own project. And each
of these is a different kind of project that Jenkins can
create. But the 101 course we're going to stick with a
freestyle project, which gives us the most flexibility. And
we're going to call this job e file system watcher. And I'll
go ahead and click Okay. Great. Now we're in the
configuration for our file system, watcher job. It's worth
noting that every Jenkins job is going to have about five
sections that you want to look at. It sounds a little
intimidating, but they're not as complicated as that. The
first is this job parameters here, job properties. And this
is do we want to pass parameters to this job? Do we want to
call it something different? Do we want to use a custom
workspace or custom build directory, these are things that
are specific to this job. The next section here is source
code management. So this is going to be less of a concern
for traditional operations teams. But if you wanted to, for
developers, or even for more of a DevOps style setup, if you
have any configuration and code or any code in source
control, you can hook up the source control here like GitHub
or AccuRev or something like that. It will link to that that
repository and hold it for changes. The next section here
build triggers. This is what is going to start the job. And
you see we have a few different options here. Some important
ones to know trigger builds remotely will allow it to be
called with a rest HTTP call. Next is build periodically. So
you can run a schedule and build it every so often. You can
also pull SEM. So as I mentioned earlier, we can hook up
source code management, if we can hold that for changes,
detect any changes and then run the job based on if changes
were detected. Finally, we have this fs trigger down here,
which is actually what I installed with my plugin. It wasn't
available to us before. And I'm going to set this up to
monitor a folder. So a little background here, I have a
folder on my C drive called the tools. And I keep a few
utilities here that I like to have around to work with. And
I want to make sure that folders backed up. So let's go into
advanced now that we've told it what to look for. And you
see, we can actually filter what things we want this job to
look at. So for example, if I was pointing this at a
configuration folder, and I only wanted it to watch for
changes to an XML or JSON or YAML file. I could use a filter
here that would point to those. Next I need to tell it how
often to check that folder. So Jenkins uses a cron timer,
which is a pretty standard thing, but if you've never worked
with them before, by clicking the question mark here, it
will actually give you a bit of an explanation as to cron
timers, and how to set one up, I want it to run as often as
possible. So I will put in five stars which as soon as we
click off of this window, we will see when it will run. And
if I go ahead and replace one of these with something else,
we see the changes that would make so I am perfectly fine
with it running as often as possible. And I'll go ahead and
click off of this question mark so we can continue with the
demo. The next section here is build environment. Build
environment is if you want to inject anything into the build
itself before it starts. This could be secrets or
environment variables or additional parameters or anything
else you might want to do. I always like to add timestamps
to the console output so I can track what's going on a
little bit better. Right. And next we have our build step,
build step is going to be invoking some kind of script. And
again, you can find plugins that will allow you to do other
things. But for the most part, it is a script that needs to
be run. We'll go ahead and add a power shell command here.
And you see also Jenkins has some environment variables that
will be available in the Jenkins job itself. We're not going
to dive into those today, but it's worth checking out. You
also have your standard environment variables ready such as
path or user home. Now if you have a more complex build, you
can add more than one build step as well. Let's go ahead and
add a batch command here. In addition to our PowerShell
command, and some of these do have advanced tabs, it's worth
checking those out. They do often hide a bunch of needed
functionality behind those. So definitely check those out.
Now, after our build step after our build is complete, it
gives us an option for a post build action. So let's go
ahead and see what's there. This would be something like
sending an email, or starting another project, or putting an
archive into an artifactory or something like that. I'm
going to end up building the other project I have here,
which is backup tools folder, which we will go into in just
a minute. But it's worth noting that this is where you do
things like send an email or update a database or monitor
something like that. I had a project once where I had a
power shell script that would go and check something on a
server once a day and then put values into an HTML report.
And it would email a report to management about the status
of that server and jobs that are run at once a day, I'll run
through Jenkins. Let's go ahead and save that. For some
reason, it doesn't show it right away when you add a
downstream job. But if we refresh the page we'llsee that now
our file system watch your job has a downstream project of
the backup tools folder job. And what that means is that
when this finishes running, it's going to start this job. So
let's go ahead and take a look here. You see I've tested
this a few times. But if we scroll down to the bottom, this
is just a PowerShell copy item from my C tools directory to
my D backup drive directory. And let's go ahead and take a
look at those for a second. Okay, so we have C tools and D
backup. As you can see, there's some tools here under Tools
and backup is empty. So let's go back to Jenkins, and we can
continue our demo. Okay, so now it's time to test it out.
I'm in my file system watcher project. And off screen, what
I'm going to do is I'm going to copy a new file into that
tools folder. And we should see this build automatically in
just a moment. There we go, our job is done. Now we can go
and click on this number one job here, we see it was
triggered by fs trigger, the change to a folder, and we go
into the log here, we can see a few more details on that. We
go back to the job information page here and then go to
console output. We can also see it was the full log of the
job. And now Jenkins will take whatever you enter in a
script console, and then run it as a temporary script of
that type. So if you look on the fourth line, For example,
it's taking PowerShell that xe and running something from C,
Windows 10 Jenkins, that looks like a randomly generated
Jenkins script, dot ps one. And that's just taking the
contents from that script window we entered earlier, making
a temporary power shell file and then running it. And you'll
see a couple lines later, or excuse me, the next line,
that's our right host that we had. So the output of that
script was successful. And the line below that is the same
thing with batch and you'll see we have a batch and
PowerShell there. Okay, and at the bottom here, it says it
triggered a new build of the backup tools folder, you'll see
we do have a build number 13. Now whereas before it was only
build number 12. Let's go ahead and go into that one as
well. And we see it was started by the upstream Project File
System watcher. And again, if we go down to console output
We'll see the right hosts that I had in there, but did it
actually copy. Let's go back to the file system and find
out. Okay, we are back in our file system here and you'll
see I the file I added was a terminal GIF. And if we go on
our right side here into the backup, we have a new tools
folder, and it mimics what is in the C tools folder.
Alright, that's it for today. Thank you for watching.