Restart a workspace through the coder api

Is there a way to directly restart the coder workspce through the coder api , or i need to first stop the workspace then keep checking for the status of the workspace once its stopped in need to hit the start endpoint ??
Solution:
Yes you can do that by making two API calls. https://coder.com/docs/reference/api/builds#create-workspace-build one with "transition": "stop" then when it completes do another with "transition": "start"...
Jump to solution
5 Replies
Codercord
Codercord6d ago
<#1319277152679755848>
Category
Help needed
Product
Coder (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Solution
Atif
Atif6d ago
Yes you can do that by making two API calls. https://coder.com/docs/reference/api/builds#create-workspace-build one with "transition": "stop" then when it completes do another with "transition": "start"
ayush
ayushOP5d ago
one help or suggestion required for my use case of the coder i have a project in the gitlab which has the application code and a coder workspace is created for that project in gitlab . So whenever the a latest code is pushed to the gitlab project , my coder workspace , should restart , so that the scripts of the workspace would pull the latest code from the project So for this use case can you suggest a good approach ?
Atif
Atif5d ago
You need to pull latest code from gitlab in your workspace whenever the upstream chnages? You can probably add a coder_script with that runs on cron or a coder_app that runs a command to pull your chnages whenever you click the button in UI.
Scott
Scott4d ago
my coder workspace , should restart
Why would you do anything different than in a normal/ local development environment scenario? Does a dev restart her laptop to get the lastest version of a repository? I don't think so. I know you are trying to automate the update of the repo, but really, that makes little to no sense. If the dev is worried about having an outdated version, she should just git pull the origin repo (again). Also, imagine the dev is trying to do some work and the workspace restarts on her willy nilly. Not good!!!!

Did you find this page helpful?