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: README.md
+74-8Lines changed: 74 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,14 @@
2
2
3
3
## Automate your GitHub workflows using Azure Actions
4
4
5
-
[GitHub Actions](https://help.github.com/en/articles/about-github-actions) gives you the flexibility to build an automated software development lifecycle workflow. With [GitHub Actions for Azure](https://github.com/Azure/actions/) you can create workflows that you can set up in your repository to build, test, package, release and **deploy** to Azure.
5
+
[GitHub Actions](https://help.github.com/en/articles/about-github-actions) gives you the flexibility to build an automated software development lifecycle workflow.
6
+
7
+
With [GitHub Actions for Azure](https://github.com/Azure/actions/) you can create workflows that you can set up in your repository to build, test, package, release and **deploy** to Azure.
6
8
7
9
# GitHub Action for Azure Login
8
-
With the Azure login Action, you can automate your workflow to do an Azure login using [Azure service principal](https://docs.microsoft.com/en-us/azure/active-directory/develop/app-objects-and-service-principals) and run Az CLI scripts.
10
+
With the Azure login Action, you can automate your workflow to do an Azure login using [Azure service principal](https://docs.microsoft.com/en-us/azure/active-directory/develop/app-objects-and-service-principals) and run Az CLI and Azure PowerShell scripts.
11
+
12
+
By default, only az cli login will be done. In addition to az cli, you can login using Az module to run Azure PowerShell scripts by setting enable-AzPSSession to true.
9
13
10
14
Get started today with a [free Azure account](https://azure.com/free/open-source)!
11
15
@@ -36,16 +40,51 @@ jobs:
36
40
37
41
```
38
42
39
-
## Configure Azure credentials:
43
+
## Sample workflow that uses Azure login action to run Azure PowerShell
44
+
45
+
```yaml
46
+
47
+
# File: .github/workflows/workflow.yml
48
+
49
+
on: [push]
50
+
51
+
name: AzurePowerShellLoginSample
40
52
41
-
To fetch the credentials required to authenticate with Azure, run the following command to generate an Azure Service Principal (SPN) with Contributor permissions:
53
+
jobs:
42
54
43
-
```sh
44
-
az ad sp create-for-rbac --name "myApp" --role contributor \
55
+
build:
56
+
runs-on: ubuntu-latest
57
+
steps:
58
+
59
+
- name: Login via Az module
60
+
uses: azure/login@v1.1
61
+
with:
62
+
creds: ${{secrets.AZURE_CREDENTIALS}}
63
+
enable-AzPSSession: true
64
+
65
+
- run: |
66
+
Get-AzVM -ResourceGroupName "ResourceGroup11"
67
+
68
+
```
69
+
70
+
Refer [Azure PowerShell](https://github.com/azure/powershell) Github action to run your Azure PowerShell scripts.
71
+
72
+
## Configure deployment credentials:
73
+
74
+
For any credentials like Azure Service Principal, Publish Profile etc add them as [secrets](https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables) in the GitHub repository and then use them in the workflow.
75
+
76
+
The above example uses user-level credentials i.e., Azure Service Principal for deployment.
77
+
78
+
Follow the steps to configure the secret:
79
+
* Define a new secret under your repository settings, Add secret menu
80
+
* Store the output of the below [az cli](https://docs.microsoft.com/en-us/cli/azure/?view=azure-cli-latest) command as the value of secret variable, for example 'AZURE_CREDENTIALS'
81
+
```bash
82
+
83
+
az ad sp create-for-rbac --name "myApp" --role contributor \
# Replace {subscription-id}, {resource-group} with the subscription, resource group details of your keyvault
87
+
# Replace {subscription-id}, {resource-group} with the subscription, resource group details
49
88
50
89
# The command should output a JSON object similar to this:
51
90
@@ -56,8 +95,35 @@ az ad sp create-for-rbac --name "myApp" --role contributor \
56
95
"tenantId": "<GUID>",
57
96
(...)
58
97
}
98
+
99
+
```
100
+
* Now in the workflow file in your branch: `.github/workflows/workflow.yml` replace the secret in Azure login action with your secret (Refer to the example above)
101
+
102
+
103
+
# Azure Login metadata file
104
+
105
+
```yaml
106
+
107
+
# action.yml
108
+
109
+
# Login to Azure subscription
110
+
name: 'Azure Login'
111
+
description: 'Authenticate to Azure and run your Az CLI or Az PowerShell based Actions or scripts. github.com/Azure/Actions'
112
+
inputs:
113
+
creds:
114
+
description: 'Paste output of `az ad sp create-for-rbac` as value of secret variable: AZURE_CREDENTIALS'
115
+
required: true
116
+
enable-AzPSSession:
117
+
description: 'Set this value to true to enable Azure PowerShell Login in addition to Az CLI login'
118
+
required: false
119
+
default: false
120
+
branding:
121
+
icon: 'login.svg'
122
+
color: 'blue'
123
+
runs:
124
+
using: 'node12'
125
+
main: 'lib/main.js'
59
126
```
60
-
Add the json output as [a secret](https://aka.ms/create-secrets-for-GitHub-workflows) (let's say with the name `AZURE_CREDENTIALS`) in the GitHub repository.
0 commit comments