![](/img/trans.png)
[英]Could any one help me how to perform Azure table storage deployment through VSTS?
[英]Could any one help me how to stop and start azure webjobs through vsts?
我在VSTS中找到了一個插件azure app服務webjob,但我無法啟動/停止webjob.Please幫助我們。 我在VSTS中運行任務時遇到以下錯誤。
錯誤:
2017-09-25T12:26:37.3203696Z Preparing task execution handler.
2017-09-25T12:26:43.2660796Z Executing the powershell script:
d:\a\_tasks\Start_cbebb02b-11c6-4e24-b5a8-0b51366d51b7\0.2.5\Start.ps1
2017-09-25T12:26:43.6830868Z ##
[error]System.Management.Automation.ParentContainsErrorRecordException: At
D:\a\_tasks\Start_cbebb02b-11c6-4e24-b5a8-0b51366d51b7\0.2.5\Start.ps1:13
char:16
2017-09-25T12:26:43.6830868Z + $WebAppName
2017-09-25T12:26:43.6830868Z + ~
2017-09-25T12:26:43.6830868Z Missing ')' in function parameter list.
2017-09-25T12:26:43.6830868Z
2017-09-25T12:26:43.6830868Z At D:\a\_tasks\Start_cbebb02b-11c6-4e24-b5a8-
0b51366d51b7\0.2.5\Start.ps1:17 char:1
2017-09-25T12:26:43.6830868Z + )
2017-09-25T12:26:43.6830868Z + ~
2017-09-25T12:26:43.6830868Z Unexpected token ')' in expression or
statement.
使用Invoke-AzureRMResourceAction
命令:
碼:
觸發的WebJob:
Invoke-AzureRmResourceAction -ResourceGroupName XXX -ResourceType Microsoft.Web/sites/TriggeredWebJobs -ResourceName [web app name]/[web job name] -Action run -ApiVersion 2015-08-01 -force
連續WebJob:
Invoke-AzureRmResourceAction -ResourceGroupName XXX -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName [web app name]/[web job name] -Action [start/stop] -ApiVersion 2015-08-01 -Force
包含多個webjobs的簡單示例腳本:
param(
[object[]]$webjobs,
[string]$website,
[string]$rg
)
foreach($wj in $webjobs){
if($wj.typeName -eq "continuous")
{
Invoke-AzureRmResourceAction -ResourceGroupName $rg -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName "$website/$($wj.name)" -Action start -ApiVersion 2015-08-01 -Force
}
else{
Invoke-AzureRmResourceAction -ResourceGroupName $rg -ResourceType Microsoft.Web/sites/TriggeredWebJobs -ResourceName "$website/$($wj.name)" -Action run -ApiVersion 2015-08-01 -force
}
}
指定參數:
-webjobs @(@{"name"="webjob1";"typeName"='continuous'},@{"name"="webjob2";"typeName"='continuous'},@{"name"="webjob3";"typeName"='triggered '}) -website XX -rg XX
public static string token = System.Configuration.ConfigurationManager.AppSettings["token"];
public static string continuouswebjobs = System.Configuration.ConfigurationManager.AppSettings["continuouswebjobs"];
public static string triggeredwebjobs = System.Configuration.ConfigurationManager.AppSettings["triggeredwebjobs"];
public static string hostName = System.Configuration.ConfigurationManager.AppSettings["DLUHostName"];
public static void StopContinuousWebJob(TextWriter log)
{
HttpClient request = new HttpClient();
request.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
request.DefaultRequestHeaders.Add("Authorization", token);
if (!string.IsNullOrEmpty(continuouswebjobs))
{
string[] jobsArray = continuouswebjobs.Split(',');
for (int i = 0; i < jobsArray.Length; i++)
{
HttpResponseMessage response = request.PostAsync(new Uri(hostName + "continuouswebjobs/" + jobsArray[i] + "/stop"), null).Result;
if (response.StatusCode == HttpStatusCode.OK)
{
Console.WriteLine("Job " + jobsArray[i] + " stopped successfully.");
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.