How to visualize deployment status and time somehow using the Gitlab’s environments feature?

What we have on each server is a ‘crontab’ that tries to deploy the environment every night. But we don’t yet have visibility whether the deployment succeeded or not, and what time it happened. Can we visualize it somehow using the Gitlab’s environments feature?

Normally, this is managed within the CI pipeline, using environment key - check the YAML reference. IMHO, this is also the easier way to do it - you may try to replace your cron job with scheduled pipeline and then you could manage this easily.

However, if you are not triggering this job from GitLab CI, then you can try making a custom script using GitLab API:

Hope this helps! :slight_smile:

1 Like

Thank you for your reply. I tried your option one. but if the deployment job is fail, environments status is not updated. status only updated for ‘Success’ scenarios. Do you know the reason?

below is my deployment job

stage: deploy
image: docker:24.0.5-cli-alpine3.18
- echo “Deploy to staging server”
- apk add --no-cache sshpass
- |
sshpass -p ‘test’ ssh -o StrictHostKeyChecking=no user@$SERVER_IP ’
cd /home/ || exit 1;
ls || exit 1;
pwd || exit 1;
docker compose pull || { echo “Docker pull failed”; exit 1; };
docker compose up -d || { echo “Docker compose up failed”; exit 1; };

url: “http://$SERVER_IP:8084/ui/index.html#/”
- schedules


I believe it always shows only the last successful deployment (the current status). The failed deployment should be seen if you click on the Environment name, and then go to Deployment history tab - there it should be a list with jobs that tried to deploy to this environment and the status.

OK. Thank you very much for your reply. :slightly_smiling_face:

1 Like