Monday, February 14, 2022

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.

No comments:

Post a Comment