Monday, February 14, 2022

Jenkins : Changing Port Number



Most services that get installed on your machine usually tend to use the the 8080 port as their default. Even when you develop a Web App, the default port is mostly 8080 unless you go and configure it to be something else. Jenkins is just one of those apps that use the port 8080 is the default.

So let’s do a quick run on changing the port number to something you would prefer especially if you missed this the first time when you were setting up Jenkins on the server.



Look for the main Jenkins Profile, file on the server. Mostly in the path : /etc/default/jenkins and use your favourite text editor to change an Environment Variable in that file.


Change Jenkins Port : Linux OS

Change that port number to the new number that you intend to use from now on and then you can save your changes. Remember that you must restart Jenkins.



The way you installed Jenkins on Mac OS plays a huge role on this one. In my case I have installed Jenkins using Homebrew Package manager. I chose to believe that you have installed it the same way. Is that’s the case then look for a Mac OS system process file. This file extension should be ending in ..plist. The path is : /usr/local/Cellar/jenkins-lts/${jenkins-version}/homebrew.mxcl.jenkins-lts.plist .


NB : Pay close attention to this path above and replace ${jenkins-version} with your target version.


Use your favourite text editor to change the port number as show in the image below :


Change Jenkins Port : Mac OS


You will notice that I changed my port number to 8001 for fun. So you go for it as well and then save your changes and remember to restart.



It’s always the little things that matter the most in the world. I hope this was helpful and you will find it useful as you are working with tools like Jenkins. Cheers!




Jenkins : Making Jenkins Run Using An Alternative Username



I was once bothered big time by Jenkins and this thing of running in some sort of a context of its own. Given that it was running under its own user name and had it’s own Maven Repo and many more things I could not run a Maven build on some Libraries for one of the organisations I was consulting at.



So I would SSH into the Linux server and try to run a Maven build and that would work but, as soon as I try automate the same in Jenkins, then I would have problems. It’s as if Jenkins was an alien on that server. I don’t know if it’s a normal thing for you as well but, it was really frustrating.

But hey, at the same time I was just finding my way around Jenkins. So after some time I learned about a few Jenkins directories. Let’s try sort that out and see if it will help you.



So one of the several solutions is to try and change the user around Jenkins. Remember that out of the box and the moment Jenkins is running as as user, “jenkins” So you are probably running as “root” or some other username that’s not jenkins.

Assuming that you running as root let’s use the root example.

Mainly you need to assign specific jenkins directories to your username, in this case “root” or whatever user you want to assign this to which is probably safer, security wise. So let’s change the following directories as follows :


  • sudo chown -R root:root /var/lib/jenkins
  • sudo chown -R root:root /var/cache/jenkins
  • sudo chown -R root:root /var/log/jenkins


Once you are done you need to change the username that jenkins is using to your preferred one, in our case we are using “root”. Using a text editor of your choice look for the main Jenkins Profile, file at, /etc/default/jenkins open it and change the 


Jenkins Username Variable


As you can see, I have commented out the original JENKINS_USER=$NAME of which Jenkins was picking up it’s own username, which makes sense. I have also replaced this with our context username, “root”

The last thing you need to do is make sure that you save your changed and then restart your Jenkins. After all this you should be able to automate a few tasks that you could not automate given the whole username issue and Jenkins running inside its own world.



I hope this was helpful and you will find it useful as you are working with tools like Jenkins. Don’t be frustrated anymore hey. Just have more fun with these Software Toys! Cheers!



Jenkins : Enabling Unix Alias Recognition



So you you are on a UNIX system and you want to work with some Aliases in your shell execution but, you hit some issues. This is because it appears that mostly Jenkins has this disabled for some reason. Remember that Jenkins runs in its own sort of context under its own “jenkins” user.

Today we are going to look at some more Unix goodies. So we are going to check out the “Shopt BuiltIn” which is a tool that allows you to make some modifications to the optional behaviour of shell. So you can switch On & Off or Toggle some values of the configurations that have an effect on the Shell behaviour.





Let’s configure a small Jenkins Job that will have an alias and try to use that alias. This is so that we can see the problem in action to make it more clear on the issue we are solving.


Jenkins Job With Alias Problem


So we have a Jenkins Job where we have our own alias named : simple_text_printout of which we also try to use in the line that follows. Now let’s see what happens when we run this Job.


Actual Jenkins Job With Alias Error


As you can see. We have an issue with the Job. Jenkins is telling us that “command not found”. So let’s check a way of trying to solve this using the “Shell Options”“shopt” command.



We want to basically change the shell behaviour so that it has the aliases toggled on. This is what we meant by changing the shell behaviour. Let’s go through the Shopt Web Manual. You will notice that to get started you need the shopt flag or indicator or command. The second thing we need to do is enable the behaviour. You will notice that you need -s to [ Enable ] and -u to [ Disable ] so this is very important. The last piece to add is to specify the behaviour we want to modify. In this case we want to enable or expand aliases so we will go for the expand_aliases behaviour identifier.

Finally in full we have shopt -s expand_aliases . Add that into your Jenkins job, save your Job and try running it again.


Enabling Aliases Behaviour On Jenkins Job


Results After Changing Job


 Jenkins is now happy. You can explore more on this shopt tool.


I hope this was helpful and you will find it useful as you are working with tools like Jenkins or even in general, may be there are some Unix distributions that don’t have this out of the box and you would like to have this behaviour.