{"id":204,"date":"2019-04-28T09:11:45","date_gmt":"2019-04-28T08:11:45","guid":{"rendered":"http:\/\/vosseburchttechblog.azurewebsites.net\/?p=204"},"modified":"2019-04-28T09:11:45","modified_gmt":"2019-04-28T08:11:45","slug":"configure-azure-devops-pipeline-agent-to-auto-reboot-after-each-job","status":"publish","type":"post","link":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/2019\/04\/28\/configure-azure-devops-pipeline-agent-to-auto-reboot-after-each-job\/","title":{"rendered":"Configure Azure DevOps pipeline agent to auto reboot after each job."},"content":{"rendered":"\n<p>Sometimes you might want a cleanly started machine (not cleanly installed, mind you) for your pipeline job. For instance, if you are running UI tests. In some situations UI tests are very brittle and might be affected by a canceled or failed previous run. Is these circumstances, restarting the agent automatically after each job can be beneficial. This is now possible with the introduction of the <code>--once<\/code> parameter of the agent (more info <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/devops\/release-notes\/2019\/sprint-150-update#run-once-agent\">here<\/a>).<\/p>\n\n\n\n<p>Start off by installing your agent as usual, and be sure to make it an interactive agent. Don&#8217;t forget to configure it to autologon, since automatically rebooting without that feature would stop our agent in its tracks rather fast. After you have done this you can add a custom cmd (you could name it customrun.cmd for instance) file to the root directory of the agent with the following contents:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>call \"C:\\agent\\run.cmd\" --startuptype autostartup --once\nshutdown \/r \/t 0 \/f<\/code><\/pre>\n\n\n\n<p>If you run this file, the agent will start and the <code>--once<\/code> parameter will force it to close after the first job is finished. The shutdown command will then immediately restart the machine.<\/p>\n\n\n\n<p>To have this file run during autologon instead of the default generated run command. You need to edit the registry as well. Start your registry editor and search for the following key:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run<\/code><\/pre>\n\n\n\n<p>Change the contents to something like the following (be sure to put in the full path to your own custom cmd file obviously):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>C:\\windows\\system32\\cmd.exe \/D \/S \/C start \"Agent with AutoLogon\" \"C:\\agent\\customrun.cmd\"<\/code><\/pre>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you might want a cleanly started machine (not cleanly installed, mind you) for your pipeline job. For instance, if you are running UI tests. In some situations UI tests are very brittle and might be affected by a canceled or failed previous run. Is these circumstances, restarting the agent automatically after each job can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/204"}],"collection":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/posts\/204\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vosseburchttechblog.azurewebsites.net\/index.php\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}