我在App Center中有一个Android应用,我想安排夜间构建。
有什么办法吗?
答案 0 :(得分:0)
今天,App Center构建doesn't yet allow us to schedule recurring builds。
幸运的是,App Center有一个complete suite of APIs,我们可以利用它来安排Azure Timer Function(本质上是一个cron job在云中)来触发每晚的构建。
有关完整的解决方案,请参见此存储库中的UITestSampleApp.Functions项目:https://github.com/brminnick/UITestSampleApp
有关完整的演练,请关注这篇文章:https://www.codetraveler.io/2019/06/06/scheduling-app-center-builds/
这显示了如何从App Center收集所需的元数据和API令牌,然后如何构建将通过App Center API触发构建的Azure Timer函数。
首先,获取Post
到App Center API所需的App Center元数据
然后生成一个App Center API令牌
此Azure计时器功能使用cron计划0 0 9 * * *
每天在0900 UTC触发。
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
const string owner = "[Your App Owner]"; //change to your app owner
const string appName = "[Your App Name]"; // change to your app name
const string branch = "[Your Repo's Branch]"; //change to your repo's branch
readonly static Lazy<HttpClient> clientHolder = new Lazy<HttpClient>(() =>
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-API-Token", Environment.GetEnvironmentVariable("AppCenterApiToken"));
return client;
});
static HttpClient Client => clientHolder.Value;
[FunctionName("AppCenterScheduledBuildFunction")]
public static async Task Run([TimerTrigger("0 0 9 * * *")]TimerInfo myTimer, ILogger log)
{
var httpContent = new StringContent("{ \"debug\": true }", System.Text.Encoding.UTF8, "application/json");
var result = await Client.PostAsync($"https://api.appcenter.ms/v0.1/apps/{owner}/{appName}/branches/{branch}/builds", httpContent);
result.EnsureSuccessStatusCode();
}
在“ Azure功能应用程序设置”中,添加在步骤2中生成的App Center API令牌,其名称为AppCenterApiToken
。