How to run a job in the background on CircleCI

If you want to monitor what is happening while running a job on CircleCI you can do this using a background job that will run alongside your other jobs using background: true.

A job that has background: true set will run while there are other jobs running but once they have finished the background job will also end, it will not run on its own if there are no other jobs.

Instructions

The following code will run as an infinite loop printing the text from the echo command every five seconds as a background job. Replacing the echo command will allow any command to run every 5 seconds. You can also set any job to run the background by adding the background: true to the end of the job as shown in the example below.

- run:
command: |
while true; do
sleep5
echo "this in running in the background"
done
background: true

Outcome

Any job which is set with background: true will continue to run in the background while other jobs are running showing any output that you have defined.

Additional Resources

The following link is specifically for recording memory usage using the background: true setting:

https://support.circleci.com/hc/en-us/articles/360043994872-How-To-Record-a-Job-s-Memory-Usage

The following link is for the CircleCI documentation for background commands:

https://circleci.com/docs/configuration-reference/#background-commands

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

Comments

0 comments

Article is closed for comments.