How to run or skip a step when a job is rerun with SSH

 

Overview:

You may want to run or skip a step if you rerun your job with SSH. You can do this using netstat to see active TCP connections. When a job is rerun with SSH circleci-agent is the PID/Program Name. You can use the code snippets below to conditionally skip or run a step when a job is rerun with SSH.  

 

To skip a step if the job is rerun with SSH: 

 

 - run: |
if [[ $(netstat -tnlp | grep -F 'circleci-agent') ]] ; then
exit 0;
fi
echo "commands you want to run when job is NOT rerun with SSH"

In the above code, echo "commands you want to run when job is NOT rerun with SSH"   is only executed when a job is NOT rerun with SSH. When a job is rerun with SSH the step will silently exit with code 0. This means the step will still be successfully run but will not impact the status of your build. 

 

Only run a step when a job is rerun with SSH: 

 - run: |
if [[ $(netstat -tnlp | grep -F 'circleci-agent') ]] ; then
echo "commands you want to run ONLY when job is rerun with SSH"
fi
exit 0;

 

Additional Resources:

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Article is closed for comments.