in this video we're going to take a look at environment variables
in github actions and how you can set them
as it says github sets default environment variables for each action run but you can also
set your own custom ones in your workflow file if you'd like so as we've seen in the previous videos
we have the workflow file we have individual jobs and then we have steps and when you're setting an
environment variable you have the ability to set them at each of those levels to show how
this works let's now hop back into our project and i've trimmed everything down just so we can
focus exactly on what we care about here display is the name of our job in this case and to set an
environment variable or multiple on this level you would write env colon and then within here enter
and tab in because now we're creating a dictionary off of this here's where you can start to set
various keys and values for example let's say we wanted to create an environment variable
called platform and then colon and then you want to provide the actual value of
this so let's say in this case we care about the platform azure and let's add two more let's say
region central and profile path profile something like that
so how would we use this let's call this first step display custom environment variables what
we'll do here is we'll add a run step i'm going to make this multiple lines we'll add the pipe
and say echo the platform is and there's two ways that you can reference this the first way
is as it shows over here which is by using this env keyword and wrapping it this way
so you could say instead of day a week platform the value of this platform it'll bring it in here
so that's one way you could do this alternatively you could say the region is and you could just do
region so the difference is here you can use this variable this way if you're using it within the
run command it's already setting that variable within the ubuntu runner and then we can just
reference it here as if it's already set whereas this style you're going to want to use if you want
to use it anywhere else outside of a run command any other part of the workflow so for example here
they're using it in this if condition if you want to use it as part of a condition or something else
within your workflow that's where you're going to want to use this this wrapper for example here
if you wanted to do this if command if platform equals central you would have to reference this
variable this way you couldn't do it like this because this can only work then the run command
let's keep this as it is and just prove how this works so i made a mistake here i see this
actually failed what i need to do is add jobs here i miss this layer here so i'm going to add
this and then we'll rerun it okay so i've made that change and pushed it and now our change is
running and after looking at it again i see i'm referring to region here and platform here and
you know i was thinking about editing this out but at the same time i'm leaving this in here because
this is the reality of being a data engineer you have these small misses that it's one word or one
character that you miss that drives you nuts and you miss it so i'm leaving it in here to show one
i'm absolutely not perfect and two for anybody else who's learning and thinks that people just
get everything right the first time that's just not the way it works here we go okay so this time
we can see it did run because i changed this to match what that should be and here we can
see it's echoing the platform is azure though it worked using it this way and it also worked using
it this way all things considered that's what i wanted to show you with this specific step
next up i want to show you hopefully a little more successfully how to use the github environment
variables there's a couple default ones here that you can use and they suggest using it where you
can for example trying to reference where certain file paths you know the file system rather than
hard coded file paths you can use stuff like this so what we'll do is add another step and
i'll just print some of these out so you can see how it works let's get rid of this if condition
we don't want those problems again so in here i'll go github actor and here we can reference
in this way again because we're running it within the run command could do it this way could do it
this way but for simplicity i'm going to keep it like this and we'll do one more i'll say
github ref push these changes so that we trigger the workflow and let's see if it prints it out
for us here we see it's running let's hop in here so it displayed the custom environment variables
this worked as expected and here we go so the default environment variables worked as well so
you can see here it's passing in these values which are defaulted from github itself and you
can use this however you want and be a little more dynamic that way and avoid having to write
things that may be given to you out of the box so i hope you found this helpful feel free to
like comment if you have any questions and i'll see you at the next video thanks for watching