Reputation: 3612
I have the following pre build script in Jenkins:
#!/bin/sh set +e
kill $(lsof -t -i:8081)
mvn -f /var/lib/jenkins/workspace/project clean package
java -jar /var/lib/jenkins/workspace/project/target/site-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev
when I run Build I have the following error message
> /usr/bin/git rev-list --no-walk 044c84323d27dc3ceee93c5eebbd1c59162b6561 # timeout=10
[giant-web] $ /bin/sh -e /tmp/jenkins6442992288874687975.sh
/tmp/jenkins6442992288874687975.sh: 2: kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
kill -l [exitstatus]
Build step 'Execute shell' marked build as failure
Finished: FAILURE
How to fix it and what is the problem because this script work fine from terminal
Upvotes: 1
Views: 296
Reputation: 32507
Script is faulty for some reasons. Either $(lsof -t -i:8081) resolves to empty string or non pid value thus the error.
[giant-web] $ /bin/sh -e /tmp/jenkins6442992288874687975.sh
/tmp/jenkins6442992288874687975.sh: 2: kill: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
kill -l [exitstatus]
This block states clearly that kill is misused
Add debuging printout to see what is the value of that statement.
SET PID=$(lsof -t -i:8081)
echo "PID value: $PID"
kill $PID
also check man for kill
to make sure you got it right and you don't need any additional switch.
Upvotes: 1