/// <summary> /// Create a job of the runbook. (see /// http://aka.ms/azureautomationsdk/joboperations for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Automation.IJobOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group /// </param> /// <param name='automationAccount'> /// Required. The automation account name. /// </param> /// <param name='parameters'> /// Required. The parameters supplied to the create job operation. /// </param> /// <returns> /// The response model for the create job operation. /// </returns> public static JobCreateResponse Create(this IJobOperations operations, string resourceGroupName, string automationAccount, JobCreateParameters parameters) { return Task.Factory.StartNew((object s) => { return ((IJobOperations)s).CreateAsync(resourceGroupName, automationAccount, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
public static async Task<JobCreateResponse> startSouceControlJob(AutomationManagementClient automationClient, String resourceGroup, String automationAccount) { var jobParams = new JobCreateParameters { Properties = new JobCreateProperties { Runbook = new RunbookAssociationProperty { Name = Constants.sourceControlRunbook }, Parameters = null } }; var jobResponse = await automationClient.Jobs.CreateAsync(resourceGroup, automationAccount, jobParams, new CancellationToken()); return jobResponse; }
public async Task <RunbookJob> StartRunbookAsync( string accessToken, string subscriptionId, string resourceGroupName, string automationAccountName, string runbookName, IDictionary <string, string> runbookParameters = null) { var credentials = new TokenCredentials(subscriptionId, accessToken); using (var client = new AutomationManagementClient(credentials)) { var parameters = new AzureModels.JobCreateParameters( new AzureModels.JobCreateProperties( new AzureModels.RunbookAssociationProperty { Name = runbookName }) { Parameters = runbookParameters }); var jobCreateResult = await client.Jobs.CreateAsync(resourceGroupName, automationAccountName, parameters).ConfigureAwait(false); return(new RunbookJob { JobId = jobCreateResult.Job.Properties.JobId.ToString(), StartDateTime = jobCreateResult.Job.Properties.StartTime, EndDateTime = jobCreateResult.Job.Properties.EndTime, Status = jobCreateResult.Job.Properties.Status, ResourceGroupName = resourceGroupName, AutomationAccountName = automationAccountName, RunbookName = runbookName }); } }
public Guid? StartRunbook(RunbookModelProxy runbookProxy, List<NameValuePair> parameters) { var jobGuid = Guid.NewGuid(); var runbook = _client.Runbooks.Get(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, runbookProxy.RunbookName); if (runbook.StatusCode == System.Net.HttpStatusCode.NotFound) return null; var jobParameters = new JobCreateParameters(); jobParameters.Name = jobGuid.ToString(); jobParameters.Properties = new JobCreateProperties(); jobParameters.Properties.Runbook.Name = runbookProxy.RunbookName; foreach (var param in parameters) jobParameters.Properties.Parameters.Add(param.Name, param.Value); var response = _client.Jobs.Create(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, jobParameters); if ((int)response.StatusCode > 299) { _output.AppendLine("Unable to start the job, please verify your connectivity and parameters and try again."); return null; } _jobCache.Add(jobGuid, response.Job); runbookProxy.IsTestRun = false; return jobGuid; }
public async Task<RunbookJob> StartRunbookAsync( string accessToken, string subscriptionId, string resourceGroupName, string automationAccountName, string runbookName, IDictionary<string, string> runbookParameters = null) { var credentials = new TokenCredentials(subscriptionId, accessToken); using (var client = new AutomationManagementClient(credentials)) { var parameters = new AzureModels.JobCreateParameters( new AzureModels.JobCreateProperties( new AzureModels.RunbookAssociationProperty { Name = runbookName }) { Parameters = runbookParameters }); var jobCreateResult = await client.Jobs.CreateAsync(resourceGroupName, automationAccountName, parameters).ConfigureAwait(false); return new RunbookJob { JobId = jobCreateResult.Job.Properties.JobId.ToString(), StartDateTime = jobCreateResult.Job.Properties.StartTime, EndDateTime = jobCreateResult.Job.Properties.EndTime, Status = jobCreateResult.Job.Properties.Status, ResourceGroupName = resourceGroupName, AutomationAccountName = automationAccountName, RunbookName = runbookName }; } }
/// <summary> /// Create a job of the runbook. (see /// http://aka.ms/azureautomationsdk/joboperations for more /// information) /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.Automation.IJobOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group /// </param> /// <param name='automationAccount'> /// Required. The automation account name. /// </param> /// <param name='parameters'> /// Required. The parameters supplied to the create job operation. /// </param> /// <returns> /// The response model for the create job operation. /// </returns> public static Task<JobCreateResponse> CreateAsync(this IJobOperations operations, string resourceGroupName, string automationAccount, JobCreateParameters parameters) { return operations.CreateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None); }