You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/load-testing/tutorial-cicd-github-actions.md
+40-26Lines changed: 40 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,11 +56,17 @@ The sample application's source repo includes an Apache JMeter script named *Sam
56
56
57
57
## Set up GitHub access permissions for Azure
58
58
59
-
The GitHub Actions workflow needs to authenticate with Azure to access Azure resources. In the sample application, you use the [Azure Login](https://github.com/Azure/login) action and an Azure Active Directory service principal to authenticate with Azure.
59
+
To grant GitHub Actions access to your Azure Load Testing resource, perform the following steps:
60
60
61
-
In this section, you'll configure your GitHub repository to have permissions to access your Azure load testing resource:
61
+
1. Create a service principal that has the permissions to access Azure Load Testing.
62
+
1. Configure a GitHub secret with the service principal information.
63
+
1. Authenticate with Azure using [Azure Login](https://github.com/Azure/login).
62
64
63
-
1. Run the following Azure CLI command to create a service principal and assign the Contributor role:
65
+
### Create a service principal
66
+
67
+
First, you'll create an Azure Active Directory [service principal](/azure/active-directory/develop/app-objects-and-service-principals#service-principal-object) and grant it the permissions to access your Azure Load Testing resource.
68
+
69
+
1. Run the following Azure CLI command to create a service principal and assign the *Contributor* role:
64
70
65
71
```azurecli
66
72
az ad sp create-for-rbac --name "my-load-test-cicd" --role contributor \
@@ -70,50 +76,56 @@ In this section, you'll configure your GitHub repository to have permissions to
70
76
71
77
In the previous command, replace the placeholder text `<subscription-id>` with the Azure subscription ID of your Azure Load Testing resource.
72
78
73
-
The outcome of the Azure CLI command is the following JSON string, which you'll add to your GitHub secrets in a later step:
79
+
> [!NOTE]
80
+
> Azure Login supports multiple ways to authenticate with Azure. For other authentication options, see the [Azure and GitHub integration site](/azure/developer/github).
81
+
82
+
The output is the role assignment credentials that provide access to your resource. The command should output a JSON object similar to this.
74
83
75
84
```json
76
85
{
77
-
"clientId": "<my-client-id>",
78
-
"clientSecret": "<my-client-secret>",
79
-
"subscriptionId": "<my-subscription-id>",
80
-
"tenantId": "<my-tenant-id>",
86
+
"clientId": "<GUID>",
87
+
"clientSecret": "<GUID>",
88
+
"subscriptionId": "<GUID>",
89
+
"tenantId": "<GUID>",
81
90
(...)
82
91
}
83
92
```
84
93
85
-
> [!NOTE]
86
-
> Azure Login supports multiple ways to authenticate with Azure. For other authentication options, see the [Azure and GitHub integration site](/azure/developer/github).
87
-
88
-
1. Go to your forked GitHub repository for the sample application.
89
-
90
-
You'll add a GitHub secret to your repository for the service principal you created in the previous step. The Azure Login action uses this secret to authenticate with Azure.
94
+
1. Copy this JSON object, which you can use to authenticate from GitHub.
91
95
92
-
1. Add a new secret to your GitHub repository by selecting **Settings** > **Secrets** > **New repository secret**.
93
-
94
-
:::image type="content" source="./media/tutorial-cicd-github-actions/github-new-secret.png" alt-text="Screenshot that shows selections for adding a new repository secret to your GitHub repo.":::
95
-
96
-
1. Enter **AZURE_CREDENTIALS** for **Name**, paste the JSON response from the Azure CLI for **Value**, and then select **Add secret**.
97
-
98
-
:::image type="content" source="./media/tutorial-cicd-github-actions/github-new-secret-details.png" alt-text="Screenshot that shows the details of the new GitHub repository secret.":::
99
-
100
-
1. To authorize the service principal to access the Azure Load Testing service, assign the Load Test Contributor role to the service principal.
96
+
1. Grant permissions to the service principal to create and run tests with Azure Load Testing. The Load Test Contributor role grants permissions to create, manage and run tests in an Azure Load Testing resource.
101
97
102
98
First, retrieve the ID of the service principal object by running this Azure CLI command:
103
99
104
100
```azurecli
105
101
az ad sp list --filter "displayname eq 'my-load-test-cicd'" -o table
106
102
```
107
103
108
-
Next, assign the Load Test Contributor role to the service principal. Replace the placeholder text `<sp-object-id>` with the `ObjectId` value from the previous Azure CLI command. Also, replace `<subscription-name-or-id>` with your Azure subscription ID.
104
+
Next, run the following Azure CLI command to assign the *Load Test Contributor* role to the service principal.
109
105
110
106
```azurecli
111
107
az role assignment create --assignee "<sp-object-id>" \
112
108
--role "Load Test Contributor" \
113
-
--subscription "<subscription-name-or-id>"
109
+
--subscription "<subscription-id>"
114
110
```
111
+
112
+
In the previous command, replace the placeholder text `<sp-object-id>` with the `ObjectId` value from the previous Azure CLI command. Also, replace `<subscription-id>` with your Azure subscription ID.
113
+
114
+
### Configure the GitHub secret
115
115
116
-
You can now use the `AZURE_CREDENTIALS` secret with the Azure Login action in your CI/CD workflow. The following code snippet describes how this works for the sample application:
116
+
You'll add a GitHub secret to your repository for the service principal you created in the previous step. The Azure Login action uses this secret to authenticate with Azure.
117
+
118
+
1. In [GitHub](https://github.com), browse to your forked repository, select **Settings** > **Secrets** > **New repository secret**.
119
+
120
+
:::image type="content" source="./media/tutorial-cicd-github-actions/github-new-secret.png" alt-text="Screenshot that shows selections for adding a new repository secret to your GitHub repo.":::
121
+
122
+
1. Paste the JSON role assignment credentials that you copied previously, as the value of secret variable *AZURE_CREDENTIALS*.
123
+
124
+
:::image type="content" source="./media/tutorial-cicd-github-actions/github-new-secret-details.png" alt-text="Screenshot that shows the details of the new GitHub repository secret.":::
125
+
126
+
### Authenticate with Azure
127
+
128
+
You can now use the `AZURE_CREDENTIALS` secret with the Azure Login action in your CI/CD workflow. The *workflow.yml* file in the sample application already has the necessary configuration:
117
129
118
130
```yml
119
131
jobs:
@@ -134,6 +146,8 @@ jobs:
134
146
creds: ${{ secrets.AZURE_CREDENTIALS }}
135
147
```
136
148
149
+
You've now authenticated with Azure from the GitHub. You'll now configure the CI/CD workflow to run a load test by using Azure Load Testing.
150
+
137
151
## Configure the GitHub Actions workflow to run a load test
138
152
139
153
In this section, you'll set up a GitHub Actions workflow that triggers the load test. The sample application repository contains a workflow file *SampleApp.yaml*. The workflow first deploys the sample web application to Azure App Service, and then invokes the load test by using the [Azure Load Testing Action](https://github.com/marketplace/actions/azure-load-testing). The GitHub action uses an environment variable to pass the URL of the web application to the Apache JMeter script.
0 commit comments