Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,

I am facing an unusual problem, i am trying to pass arguments to a build script through Jenkins command line, however i am not able to do so.

When i capture and print the arguments it prints empty.

Brief code is:
argument=$1

echo "ARGUMENT: $argument"

set -eu
set -o pipefail
set +u

...somecode...
...somecode...
...somecode...

set -x
set +u
if [[ "$argument" == "somevalue" ]]; then /// Argument does not seem to populate
    execute a script
else
    execute another script
fi
set -u

...somecode...
...somecode...
...somecode...

echo "ARGUMENT: $argument" /// Argument does not seem to populate

if [[ "$argument" == "somevalue" ]]; then
    execute a script
else
    execute another script
fi


i print any value of arguments after this, it does not capture.
Any suggestion help would be helpful.

Thanks and Regards,
Rahul

What I have tried:

I removed the SET -u and -x etc flags and printed variables.
I also used a workaround to store the variable in a file read it in the script and then use it. But, this is not the intended way to go about it.

Observation:
- When I run this script via my terminal video the script works fine.
- Executing the script from Jenkins console window does not seem to capture the argument.
Posted
Updated 11-May-23 18:30pm
v2
Comments
Richard MacCutchan 11-May-23 4:19am    
I just ran that script and it works fine.
Rahul VB 12-May-23 0:22am    
Thanks for trying. Actually, I run this script through the Jenkins console window. Somehow, i don't see the arguments being populated. When i run this script through my terminal window it works fine, but I cant seem to understand what's the change via Jenkins console window.
I will update my question...
Richard MacCutchan 12-May-23 3:54am    
The only information you have provided is the above sctipt which, as you say, works correctly. No one here can guess what the Jenkins system is doing.
Rahul VB 16-May-23 7:48am    
Okay, so i found the solution, there was another script being called by this. It was very implementation specific. The arguments passed to this script were being unset for some weird reason.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900