Skip to content

Commit 37ff18b

Browse files
authored
Merge pull request #185810 from ntrogh/alt-github
Restructured CI/CD authentication section
2 parents 02ecb93 + d38892a commit 37ff18b

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

articles/load-testing/tutorial-cicd-github-actions.md

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,17 @@ The sample application's source repo includes an Apache JMeter script named *Sam
5656

5757
## Set up GitHub access permissions for Azure
5858

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:
6060

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).
6264

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:
6470

6571
```azurecli
6672
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
7076
7177
In the previous command, replace the placeholder text `<subscription-id>` with the Azure subscription ID of your Azure Load Testing resource.
7278
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.
7483
7584
```json
7685
{
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>",
8190
(...)
8291
}
8392
```
8493
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.
9195
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.
10197
10298
First, retrieve the ID of the service principal object by running this Azure CLI command:
10399
104100
```azurecli
105101
az ad sp list --filter "displayname eq 'my-load-test-cicd'" -o table
106102
```
107103
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.
109105
110106
```azurecli
111107
az role assignment create --assignee "<sp-object-id>" \
112108
--role "Load Test Contributor" \
113-
--subscription "<subscription-name-or-id>"
109+
--subscription "<subscription-id>"
114110
```
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
115115
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:
117129
118130
```yml
119131
jobs:
@@ -134,6 +146,8 @@ jobs:
134146
creds: ${{ secrets.AZURE_CREDENTIALS }}
135147
```
136148

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+
137151
## Configure the GitHub Actions workflow to run a load test
138152

139153
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

Comments
 (0)