now let's talk about the workspace and the output that is getting generated in the workspace.
So in the workspace, in the target directory, we are seeing the artifact.
Now, every time I run the job, this artifact will get replaced with a newer artifact. And I'll be running
the job if there is any career change.
So let's say I deploy this artifact, it works fine.
Then there is a new code change I run the build.
Build one more time.
So now the new artifact will replace the old artifact and you deploy new artifact to your server and
things break.
Now you want to roll back to the previous artifact or you want the previous artifact.
But that's gone.
It was overwritten.
So to preserve all the artifacts, you can do some versioning, you can do a very simple versioning
through executing some shell commands.
So that's what we'll do in this video.
And we will be also talking about plug ins will be installing some plug ins for versioning.
So.
As this target directory is really volatile, if someone runs mvn clean, everything goes off, right. So
we'll do this, now, I will create again one more job and I will name it as versioning
builds.
Freestyle, and I'm going to copy everything from the job.
OK.
Scroll down and I'm going to remove archive the artifacts here, because it will start storing this
artifact in two different different directories with different different build numbers, and that will
take more space.
So I'm going to take that out now.
So let's just first save and run this job.
OK, so build completed successfully and we should have artifact in our workspace.
Nice.
Now, mind you, I'm not just talking about versioning over here, we'll be learning a few more extra tricks
in Jenkins' . We will be doing a proper and better versioning through other tools for now, just some hands
on in understanding versioning your builds.
So no right or wrong, for now, it's just getting comfortable with Jenkins.
OK, so our artifact vprofile-v2.war
That's an artifact.
I'm going to copy its name because I'm going to copy this artifact with a different name every time
the job runs.
So configure the job, come down at the build section.
And after the build completes, we can add one more step, I will say execute shell.
And first, I will say, mkdir
Create a directory.
I will give -p option, so it does not throw me error every time and I will create a directory called versions
Then I'm going to say copy target/vprofile-v2.war
OK, that's the artifact path, to, versions slash, and now I am going to copy it into versions directory.
every time the job runs, it will copy into versions directory.
But then again, it will be overwriting things right if you give some name over here.
So there should be some dynamic names.
So I will be using a variable $BUILD_ID
BUILD_ID
So I will say vprofile-V$BUILD_ID
.war, Now jenkins' have so many variables.
Let's go to the Jenkins' environment variable, you can just do a simple Google and find this URL Jenkins
environment variable and you should get this link.
If you scroll down over here, you should see different environment variable, you have build no, build ID
build url, node name, job name, build tag and you see many, many.
I know not that many, but we'll be adding some more variable also. So I am using BUILD_ID, this is going
to return me the build ID number.
So the current job number.
And that's what I'm going to give in the artifact for versioning V$BUILD_ID, so it could be two,
three, four.
Nice trick, OK.
Let's do this.
And I'm going to run the build few times and then pause my screen and resume it once I run few builds
OK, so I have done the job.
Build ID two, three and four.
Let's check in the workspace. Should see versions directory.
And you see different versions of the artifact, and that's nice.
Can we use some other versioning format?
What what if I want to specify my own, like a user argument
So Jenkins, Jenkins job has also one option here in the general.
settings, this project is parameterized, this is going to take a user input, like in bash script.
We have seen "read" that takes the user input like that.
So add parameter and we can go with string parameter.
So we can give a variable name over here, we'll say variable name, let's say version
OK, I'll keep it capital.
You know, it's easy to recognise.
VERSION. Now, when I run this job, it is going to ask the user, what is the value of VERSION?
I enter the value and it's going to store it into this variable and then I can use that in my job.
All right, so let's.
Copy this.
And hash, comment, that line and this time let's use the VERSION, $VERSION, let's save this
Now, you don't get "build now" you get "build with parameters". You click on this and it is going to ask
you the value.
So let's say I want to give 4.5.
Build
So that 4.5 will be stored in the variable version, which we are using to give the artifact a name.
OK, let's check in the workspace.
versions and....
But something's wrong, it did not take the version.
Let's check the job.
OK, that was capital, right, VERSION capital, I have given here a small version.
All right.
In small, that is wrong.
Yeah, let's save that.
So variable name, its case sensitive, of course, let's do it once again this time I will say.
5.5.
OK, let's check the workspace.
versions
OK, there you go.
V5.5, that's taking input from the user, I do not recommend that you make your jobs interactive
because this will create problems later.
But if you don't have any other way, then you have to take it right.
Well, that can be able to solved, the problem.
That will come when we are going to do continuous integration, continuous delivery.
We're going to link multiple jobs together.
And if your job is it's asking parameters, then that will break the chain. It willmake the job interactive.
There's a way of passing that also automatically, but it will be a problem anyway.
So try avoiding taking parameter from user.
OK, you will say, I want a better version now.
Right, that four, five, six, that's not working out for me, I need a proper versioning like
build stamp like a timestamp and that's not directly available, but that is available through
plug ins.
So now let's go to plug ins.
Click on Dashboard managed jenkins' and manage plug ins.
So welcome to the powerhouse of Jenkins', this is where the Jenkins' gets its all its powers, all
its features.
So you have 2 tabs over here. Updates.
If you see any old plug in, if there is any new update for a plug in, you'll get it all here.
Available section, you can search for a plug in and install it in the never
Jenkins version it does not show the list of plugins, but you can give the name of a plug in and it will search
it for you.
Install section.
You should see the installed plug. So, says many plug ins that we installed at the post installation
time when we said, you know, Unloack Jenkins that time and one plug in may have dependencies.
So you see many plug ins over here, some plugin you get uninstall options someplace you don't.
OK, that could mean that, you know, this plug in is dependent on some other plug in and it cannot
be installed.
Oh sorry, uninstalled
You see, it's telling you, this plugin cannot be uninstalled, it has one or more install dependence.
Now, in this version of Jenkins, the latest version in December 2020 really gives this one.
But in all times we don't use to get this.
And that's not very old time.
OK, so you how many plug ins with it?
Advanced section.
If you're not able to find and download the plugin because that actually searches in the Internet,
maybe you are behind a proxy server.
So if you're behind a proxy server, enter the proxy server, details the port, no username and password.
And once you enter this submit and then you have to restart Jenkins and you can restart Jenkins by,
you know, to log in the Jenkins instance and restart or you can do it from here also.
OK, if you logged in as admin user, you can say 8080/restart.
OK, you hit enter.
And it will ask you, are you sure you want to restart. Now if there are no any jobs running or schedule
jobs, you can restart, OK, but otherwise take a downtime before you start.
Otherwise, all the jobs that are running will fail.
OK, coming back, so coming through the available section, You really don't get the list of plug
ins now and that makes sense.
You know, there are now tons of plug ins.
It was almost now difficult to show all the plug ins in a page.
But you can make a search like for example, I'm looking for a plug in that has something to do with
AWS
AWS Web services SDK, pipeline, AWS ec2. OK, this plugin has an integrated
with Amazon Ec2, S3 publisher if you want to store your artifact to S3 Buckett, right.
So if you just typed S3 right, you see so many AWS related plugins.
Right, or maybe you want to do some test or some test related X unit.
Performance, a robot framework, ms test, umnit, selenium, html reports, and so as per your
use case, what you want to integrate?
You know, I just type test over here and you see the list.
This is crazy.
See that? that many you plugins.
OK.
Find some tool that you're already using in your career, in your day to day life.
See that if there is any plugin available for that.
All right, if you just say git, you should see a lot git plug ins, see, just for git.
All right, Docker, kubernetes, azure, Google cloud, selenium, different, different tools, technologies,
cloud provider, you will find plug ins for them and the list just grows every day.
We are here to look for a plugin that gives us the timestamp.
OK, Timestamp.
OK, so you have build time stamp and you have zen time stamp, you have secondary timestamp.
OK, so whatever you feel,
You can select that and that should give you this variable BUILD_TIMESTAMP or Zentimestamp
stamp it up for adoption, oh the development of this maybe stopped.
You know, it is you know, someone wants to adopt it.
OK, we'll go with Zentimestamp now.
Say installed without restart.
So when I click on Install without restart, it will install the plugin and any dependencies that has.
Let's go to Dashboard.
OK, now let's go to the versioning build job
Configure, I'm going to remove this.
This project is parametrized, and I get over here one option now. Change, date patter and for build
timestamp.
So you have to set the pattern on BUILD_TIMESTAMP variable and you can click on this question mark.
You get here, this is the format, your month, date, hour, minute seconds, like I want
just 2 yy and hours and minutes, paste it and make some changes here.
I will say.
And then hyphen then month hyphen then a underscore, OK, that's how I want the value.
OK, so set that as per your requirement and then I'm going to use that variable.
OK.
So let's comment this one also.
We will say BUILD_TIMESTAMP .
When you're watching this video, if you find any better plug in for the BUILD_TIMESTAMP, you can use
you are free to use that.
There's no hard and fast rule whatever suits your need.
We will say V$BUILD_TIMESTAMP and why not we give BUILD_ID also hyphen a dollar bill, underscore ID both.
Let's save.
And let's see build now.
OK, that completed let me check in the workspace, versions and oh boy, see that, 20 12 13 and then the date
and time.
The date & time, by the way, is the Jenkins' instance, date and time.
It's in UTC format.
It's not our desktop time, if that is wrong.
Make sure you fixed the date and time and then you run this .
Let me run it a few more times, like in a gap of a minute.
You know what, I change the little format of it.
BUILD_ID first
Right, so control X.
BUILD_ID-BUILD_TIMESTAMP to make this look better.
build now.
OK, so I have run build few more times, and now if you check in version, oh boy, that is some problem.
OK, that is a problem.
Double dollar there and here, there is no dollar.
OK, typographical error, that should fix it.
And now let me run it again.
OK, let's check now in the workspace versions.
You have V11-20 and some blah, blah, blah version, the timestamp, really, so you see that's
a very unique combination.
Now combining Build ID with Bill Timestamp.
So I'm sure now I'm going to get unique numbers, but they're still in my workspace.
They're still in the jenkins' server and slowly it will start taking the disk space.
So we need to put it somewhere else, not in.
Jenkins' Jenkins is our continuous integration server, not storage.
So we are going to ship our artifact to some other place that will see next.