Most of the time, the target status in the deployment group shows as offline, even though the server is running. I am unsure why this occurs. When this problem arises, I usually manually run the cmd.run command in the vstsagent directory on the server. I need to create a PowerShell script that runs on the server every hour. This script will check the status of the target in the Azure DevOps deployment group. If the target is offline, despite the server being online, the script will update the target status in the Azure DevOps deployment group to online. I already have the script. To test the script, I need to simulate the target status as offline in Azure DevOps. How can I set the target status to offline? Alternatively, please suggest another way to ensure that the target status remains online when the server is running. We are using an in-house server in my company.
below is the script
$agentName = "Hosted Agent"
$poolId = 9
$projectUrl = "https://dev.azure.com/empiricaledge/demo-jazi"
Check if the agent is offline
$agentStatus = & "$env:SYSTEMDIALOGSHELLEXECUTIONPOLICY" .\config.cmd status
if ($agentStatus -like "offline") {
If the agent is offline, bring it online
& "$env:SYSTEMDIALOGSHELLEXECUTIONPOLICY" .\config.cmd --unattended --url $projectUrl --auth PAT --token ixzblm6i2ubw3vonwemukwzc2grdcddlho6oifavmqzdnvdaetzq --pool $poolId --agent $agentName --replace --acceptTeeEula --work '_work' --runAsService
}
how to make target status in azure devops offline to test that script .or give me another way to make status online always if server is running