A
A
Alexander F2021-05-13 20:38:08
bash
Alexander F, 2021-05-13 20:38:08

How to define variables in a bash script run by Jenkins?

I have a conditional script that checks for a process on port 8080, writes its id to a variable, and kills by the value of that variable. When run through the standard shell, everything works fine. But when I run this file through jenkins (in the build -> execute shell section I write the full path to the file), then this variable turns out to be empty.
Here is an example script:

#$/bin/sh
for i in 1 2 3 4 5
do
  echo "Looping ... number $i"
done

pid="$(/usr/bin/lsof -ti tcp:8080)"
echo $pid


when run from bash, all variables are shown, when run via jenkins, only variables from 1 to 5 are shown, and 'pid' is not displayed.
How to correctly define a variable?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2021-05-13
@Filex

first, through jenkins, simply execute
/usr/bin/lsof -ti tcp:8080
make sure that the command returns PID
and then solve it, the command does not work or the variable is not passed

A
Alexander F, 2021-05-14
@Filex

The lsof command doesn't really work; I'll look into that direction, thanks!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question