My GitLab CI job failed. The message I have is
ERROR: Job failed: exit status 1. This message is not informative enough for me to troubleshoot the error.
I am implementing CI/CD for a Node.Js Express application. Before I build and deploy the Server application, I am gracefully stopping / shutting-down the instance of the application that is actually running.
This is what I am trying to do inside the
However, when I run the stop job, Gitlab runner will fail with the message
ERROR: Job failed: exit status 1.
This is my code, inside
stages: # List of stages for jobs, and their order of execution - stop stop-job: # This job runs in the <stop> stage, which runs first. stage: stop script: - echo 'Stopping job ...' # Send a kill / shutdown message to a server application listening on port 80 - echo 'shutdown' | nc localhost 3000 || echo 'No process listening on port 3000' - | while true; do # Count the process using port 80 process_count=$(lsof -i :80 | grep LISTEN | wc -l) # Check if no process is using port 80 if [ "$process_count" -eq 0 ]; then echo "There is no application or process using port 80" break fi echo "Port 80 is currently in use. Retrying in 5 seconds..." # Wait 5 seconds before we retry again sleep 5 done # We are out of the loop and the current instance using port 80 is closed - echo "Stopping job completed!" only: - main - echo 'Stopping job completed!'
I believe the error seems to happen around this part of the code.
while true; do # Count the process using port 80 process_count=$(lsof -i :80 | grep LISTEN | wc -l)