-1

PFA 6 PFA 2 PFA 3 PFA PFA 4 PFA 5 I have some triggered jobs running in Azure. I have created scheduler jobs for those jobs in Azure so that whenever I disable it will stop running the triggered jobs instead of killing. But I want to disable those scheduler jobs from VSTS using plugin or Powershell script. I can stop and start Continuous webjobs using Powershell scripts but triggered jobs/scheduler jobs I am not sure how to disable using Powershell/Plugins/Tasks from VSTS definitions.

PDBR
  • 331
  • 1
  • 7
  • 17
  • 2
    Please [edit] your question to show [the code you have so far](http://whathaveyoutried.com). Most of us here are happy to help you improve your craft, but are less happy acting as short-order unpaid programming staff. Show us your work so far as a [mcve], the result you were expecting and the results you got, and we'll help you figure it out. It may help to re-read [ask]. – Toby Speight Jun 20 '18 at 14:12
  • Hi Toby, So far I don't have script to disable the scheduler jobs.So that's why I am asking at lease if there is any plugin available in VSTS market to disable and enable the triggered jobs please do let me know.I tried searching many plugins and solutions but unable to find the solution and that too I am new to VSTS and Azure.Kindly understand . – PDBR Jun 21 '18 at 06:22

2 Answers2

1

You can add an Azure Powershell Script Task and add the script below to Enable/Disable the scheduler jobs:

Set the Job to "Disabled":

Set-AzureRmSchedulerHttpJob -ResourceGroupName ABC -JobCollectionName ABC -JobName ABC -JobState Disabled

Set the Job to "Enabled":

Set-AzureRmSchedulerHttpJob -ResourceGroupName ABC -JobCollectionName ABC -JobName ABC -JobState Enabled

If you want to enable/disable the JobCollection, you can use Enable-AzureRmSchedulerJobCollection and Disable-AzureRmSchedulerJobCollection Command:

Enable-AzureRmSchedulerJobCollection -ResourceGroupName ABC -JobCollectionName ABC

Use the script below:

$JobC = Get-AzureRmSchedulerJobCollection -ResourceGroupName jobcollection -JobCollectionName jobcollection

If ($JobC.State -eq "Enabled")
{
    Write-Host "JobCollection is enabled, disabling it..."
    Disable-AzureRmSchedulerJobCollection -ResourceGroupName jobcollection -JobCollectionName jobcollection
    Write-Host "JobCollection is disabled now."
}
Else
{
    Write-Host "JobCollection has already been disabled."
}
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
  • When I run the enabled command which you gave in the above comments its throwing an error below:My Job collection is in Disabled mode but its throwing the below error: ##[error]Cannot perform job operations on job collection 'ParentJobs-Dev' since it is in state 'Stopped'/'Disabled'. Please change the collection state to 'Started'/'Enabled' before attempting job operations. – PDBR Jun 28 '18 at 13:44
  • @PDBR The error message indicated that the JobCollection was disabled. So you need to enable the JobCollection first and then you can enable the jobs in it. The command is used to enable/disable SchedulerJobs. Do you want to enable/disable Jobs or JobCollection? – Eddie Chen - MSFT Jun 29 '18 at 00:53
  • I want to stop/disable the scheduler job collection so that associated triggered jobs will also get stopped/disabled – PDBR Jun 29 '18 at 05:24
  • @PDBR Then you can change to this command: https://learn.microsoft.com/en-us/powershell/module/azurerm.scheduler/disable-azurermschedulerjobcollection?view=azurermps-4.4.1 – Eddie Chen - MSFT Jun 29 '18 at 05:29
  • As per the link which you shared I can able to disable and enable the scheduler job collection but when the state of scheduler job collection is in disable and if I run the the disable script its throwing the error like this: Operation returned an invalid status code 'Conflict' – PDBR Jul 10 '18 at 10:14
  • I can't able to run the disable script when the state is disable and can't able to run enable script when the job collection state is enable.How to avoid/fix this issue? – PDBR Jul 10 '18 at 10:16
  • chen-MSFT, Can you please help me on this? – PDBR Jul 11 '18 at 06:53
  • @PDBR You can run Get-AzureRmSchedulerJobCollection command to get the JobCollection status first and determine if it is needed to run the following command to enable/disable the JobCollection. – Eddie Chen - MSFT Jul 11 '18 at 06:59
  • Chen-MSFT, Could you please explain the scenario with the PowerShell script please ? I can see the status with Get-AzureRMSchedulerJobCollection command but if status is already in Disable then how can I disable through VSTS with the Powershell script.Its failing with the conflict error which I mentioned earlier.How can I handle this issue/scenario? – PDBR Jul 11 '18 at 10:54
  • Can you help me with the script ,suppose if the state is disable it should skip running the disable command (Disable-AzureRmSchedulerJobCollection -ResourceGroupName abc -JobCollectionName def ) and if it is not disable then it should run disable command.How can I write script in PowerShell. – PDBR Jul 11 '18 at 10:58
  • chen -MSFT, Thanks a lot for your solution.Much appreciating for your answer.I do accept this answer. – PDBR Jul 12 '18 at 06:43
0

I am afraid you can’t disable scheduler jobs, you may full stopping a web app.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53