in this video we're going to go through how to add multiple jobs to your github
action workflow in the previous video we created this workflow here that has one job called build
that has these steps but sometimes you may want to have multiple steps to split up the work and
organize it a different way so let's walk through how you can actually do that
as mentioned here we have our initial job that we built in the previous video and to build another
step here it's as simple as adding another layer under this jobs component right here so what i'm
going to do is copy everything from the name of the job to the first step just to keep the
indentation and under the last line here i'm going to get all the way to the left and paste this in
and this time instead of calling it build let's just say we want to call it something else like
display we'll run this job using the same runner this linux ubuntu latest runner and in this case
we're just going to do something simple we're not even going to worry about checking anything out
i'm actually going to do a run command but what we'll do we'll give this a name and we'll say
print a value again this is just an example to show you what a different job will look like
the actual steps i'm not too concerned about what we'll do is we'll use the run action and say echo
hello from another job save now i'm going to check this in and push it to our branch this will
go to our test ci branch this is the one we're working in and if you look at the on component
of this workflow we're saying when anything gets pushed to this branch it'll run
so we should expect this to run and here we do see it ran already completed so it was quick
now we have build we can see all these steps that were run and then display
just printed the value hello from another job and it came through here and printed it
so just like that we were able to split it up and you can think about how you would want to do that
and one thing i'll call out here is if you go to summary we see that these were run in parallel
they're not dependent on each other when the job starts it's going to kick off both of these at the
same time and there's no real relationship between these two or dependencies or anything like that
let's talk about some things you could do if you wanted to make some sort of dependency between
them maybe you want one to run first and then only run the second job once it's done how would you
do that let's take a look at the syntax here the github action syntax and what we're going to look
at is this needs identifier and it looks something like this really all we would add here is needs
and then the name of whatever job you want it to be waiting for or dependent on and that's
it it's as simple as that in our case we say jobs jobs and instead of job one hours is called build
job two display if we want to change it so that display only runs once build runs
we would add something like this needs build and again this means that it's only going to run after
this one let's go ahead and commit that change and push it to now see what this looks like over here
we refresh we see this is now here and here this now looks a little bit different right
now we can see build is running and we only see build over here this is all that's running so far
and then now this completed it'll move on to display now display shows up here as well and
we can see this did not start until this build one finished pretty straightforward another thing to
add here is if you had multiple jobs in a row that you wanted let's say we had another one
here in this case if job one and job two you can create this span and say this job three
can only run once both of these are finished so it'll depend on this one and this one and it'll
like it says here run in a sequential order and you would see that one two three like this here
the last thing i want to call out is dealing with potential errors and whether or not you want
a dependent job to run if one before it fails let's say there's a scenario where you have these
dependent on each other so display is dependent on build but if build fails you still want
display to run currently if this is dependent and this one fails this is not going to run
but if you do want that to still run you can use this if
always condition here it's conditional expression so that it always runs regardless of whether
they're successful or not so let's test this out let's say it still needs it but we'll add this if
always condition and what we'll have to do here is find a way to purposely error this so let's
do something like this because this file doesn't exist so i'm hoping that this will actually fail
this job but this would still run so go ahead and push that up and let's see what this looks like we
would expect this to fail because i'm assuming it's going to fail because it won't be able
to find that file because it doesn't exist and there it failed but yet this one is still running
we can see this failed you know doesn't exist and this one ran no problem successful and we were all
good that's just another subtlety about these dependencies that you can do if you wanted to
and that'll do it for this video hopefully you found this helpful and if you did please
feel free to like the video subscribe i'll be uploading videos every week on
similar topics and i'll see you at the next video thanks for watching