> ## Content Index
> Fetch the complete content index at: https://codetraveler.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# Schedule Recurring Builds in App Center
- URL: https://codetraveler.io/2019/06/06/scheduling-app-center-builds/
- Published: 2019-06-06T20:51:46.000Z
- Updated: 2019-06-06T21:21:00.000Z
- Description: Leverage an Azure Timer Function (a cron job in the cloud) to trigger a build every night in App Center Build
- Author: Brandon Minnick
- Tags: app center, visual studio app center, iOS, Android, VS App Center, continuous integration, mobile, azure, functions, azure functions, API, Automation, C#, .NET, Timer, Cron, schedule, build, schedule build, recurring, recurring build, schedule recurring build, how to schedule builds, schedule builds, Xamarin

Let's explore how to schedule recurring builds in [App Center](https://azure.microsoft.com/services/app-center?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io) using [Azure Timer Functions](https://docs.microsoft.com/azure/azure-functions/functions-bindings-timer?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io)

Today, [App Center Build](https://docs.microsoft.com/appcenter/build?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io) offers a continuous integration solution for iOS, Android and UWP apps that will trigger each time we commit code to our repository. However, it [doesn't yet allow us to schedule recurring builds](https://github.com/microsoft/appcenter/issues/328?ref=codetraveler.io). 

Luckily, App Center has a [complete suite of APIs](https://docs.microsoft.com/appcenter/api-docs?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io) we can leverage to schedule an [Azure Timer Function](https://docs.microsoft.com/azure/azure-functions/functions-bindings-timer?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io) (essentially a [cron job](https://en.wikipedia.org/wiki/Cron?ref=codetraveler.io) in the cloud) to trigger a build every night.

This walkthrough shows how to gather the required metadata and API Token from App Center, then how to build an Azure Timer Function that will trigger a build via the App Center APIs.

For a complete solution, see the UITestSampleApp.Functions project in this repo: [https://github.com/brminnick/UITestSampleApp](https://github.com/brminnick/UITestSampleApp?ref=codetraveler.io)

## 1\. Get App Center Metadata

First, let's grab our App Center app's name, owner and branch metadata

1. In the [**App Center Portal**](https://appcenter.ms/?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io), click into the app
- **Note:** My app is called **UITestSampleApp, Android**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture5.png)

Click Into App

2\. In the **App Overview** page, click on the **Build** 

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture6.png)

Select Build Icon

3\. On the **Branches** page, click into the branch for which you'd like to schedule a recurring build

- **Note:** I am using the **master** branch

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture7.png)

Click Into Branch

4\. On the **Builds** page, using the URL, copy the values for the **Owner**, **App Name** and **Branch**

- **Note:** The URL will follow the following pattern: *https://appcenter.ms/users/{owner\_name}/apps/ {app\_name}/build/branches/{branch\_name}*

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/AppCenterMetaData-1.png)

Collect Metadata

## 2\. Generate App Center API Token

Next, let's generate a token in App Center that we'll use to access our API.

1. In the [App Center Portal](https://appcenter.ms/?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io), on the top-right, click on your profile photo
2. In the settings drop-down, select **Account Settings**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture1.png)

3\. On the **Account Settings** page, click **API Tokens**

4\. On the **API Tokens** page, select **New API Token**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture2.png)

New API Token

5\. On the **New API Token** page, enter a **Description**

- **Note:** For my description, I used **Azure Timer Function API Token**

6\. On the **New API Token** page, select **Full Access**

7\. On the **New API Token** page, select **Add new API token**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture3.png)

Add new API token

8\. On the **API Tokens** page, click the copy icon to copy the API Token to the clipboard

- **Note:** We will use this API token later for our Azure Function

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture4.png)

Copy API Token

## 3\. Create Azure Timer Function

Now, let's create an [Azure Timer Function](https://docs.microsoft.com/azure/azure-functions/functions-bindings-timer?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io) to schedule a recurring build

1. In the [Azure Portal](https://portal.azure.com/?WT.mc%5Fid=appcenterbuilds-codetraveler-bramin&ref=codetraveler.io), click the **Create a Resource** button

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Picture9.png)

New Azure Resource

2\. In the search bar, enter **Function App**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/FunctionAppSearch.png)

Search Function App

3\. In the search results, select **Function App**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/SearchResults.png)

Function App Search Results

4\. On the **Marketplace Dashboard**, select **Create**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/CreateFunctin.png)

Create Function

5\. On the **Create Function App** page, enter the following details:

- **App name:** \[Your function app name\]  
  - **Note:** The app name must be unique as it is used in the URL
- **Subscription:** \[Select your Azure Subscription\]
- **Resource Group**  
  - Create New
  - AppCenterFunction
- **OS:** Windows
- **Hosting Plan:** Consumption
- **Location:** \[Select the location closest to you\]
- **Runtime Stack:** .NET
- **Storage**  
  - Create New
  - \[Your storage account name\]
- **Application Insights:** \[Use defaults\]

6\. On the **Create Function App** page, click **Create**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/CreateFunction-1.png)

Configure Function App

7\. Stand by while the Function App is deployed

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/DeploymentProgress.png)

8\. Once the deployment has finished, on the Azure Portal, select the notification button (bell icon)

9\. In the **Notifications** menu, select **Go to resource**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/GoToResource.png)

Go To Resource

10\. On the **Function App Dashboard**, next to **Functions**, click the Plus Sign (**+**)

11\. On the **Quickstart** dashboard, select **In-Portal**

12\. On the **Quickstart** dashboard, click **Continue**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/InPortalFunction-2.png)

Create In-Portal Function

13\. In the **Quickstart** dashboard, select **Timer**

14\. In the **Quickstart** dashboard, select **Continue**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/InPortalTimerTrigger.png)

Create Timer Function

15\. In the **run.csx** editor, enter the following code

- **Note:** Change `owner`, `appName`, and `branch` to match the values retrieved in the previous step, *Get App Center Metadata*

```csharp
using System;

public static async Task Run(TimerInfo myTimer, ILogger log)
{
    const string owner = "bminnick"; //change to your app owner
    const string appName = "uitestsampleapp"; // change to your app name
    const string branch = "master"; //change to your repo's branch

    var client = new HttpClient();
    client.DefaultRequestHeaders.Add("X-API-Token", Environment.GetEnvironmentVariable("AppCenterApiToken"));

    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();
}

```

16\. In the **run.csx** editor, click **Save**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/SaveCSX-1.png)

Save run.csx

17\. In the **Functions Dashboard**,on the left-hand menu, select **Integrate**

18\. In the **Integrate** dashboard, in the **Timestamp parameter name** text box, enter **`myTimer`**

19\. In the **Integrate** dashboard, in the **Schedule** text box, enter your cron schedule

- **Note:** I am using `0 0 9 * * *`, which means my Timer Function will run at 0900 UTC every day

20\. In the **Integrate** dashboard, click **Save**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/Integrate-1.png)

21\. On the Functions dashboard, on the left-hand menu, select the name of your **Function App**

- **Note:** My Function App is named **AppCenterFunction**

22\. On the Functions **Overview** Dashboard, select **Configuration**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/FunctionsConfiguration-1.png)

Function app settings

23\. In **Application Settings**, click **New application setting**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/NewApplicationSetting.png)

New Application Setting

24\. In the **Add/Edit application setting** window, in the **Name** text box, enter `AppCenterApiToken`

25\. In the **Add/Edit application setting** window, in the **Value** text box, enter the App Center API Token generated in the earlier step, *Generate App Center API Token*

26\. In the **Add/Edit application setting** window, click **Update**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/ApiToken.png)

Add AppCenterApiToken

27\. In **Application Settings**, click **Save**

![](https://storage.ghost.io/c/dc/c2/dcc2e43e-24f8-46bb-a899-9c446f3ef794/content/images/2019/06/SaveApplicationSettings.png)

That's it! We now have created an Azure Timer Function that will trigger an App Center Build.