Skip to content

Commit 1f09c2c

Browse files
authored
Update README.md (Azure#28)
1 parent eaef5fc commit 1f09c2c

1 file changed

Lines changed: 74 additions & 8 deletions

File tree

README.md

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
## Automate your GitHub workflows using Azure Actions
44

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.
68

79
# 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.
913

1014
Get started today with a [free Azure account](https://azure.com/free/open-source)!
1115

@@ -36,16 +40,51 @@ jobs:
3640
3741
```
3842
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
4052

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

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 \
4584
--scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \
4685
--sdk-auth
4786

48-
# 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
4988

5089
# The command should output a JSON object similar to this:
5190

@@ -56,8 +95,35 @@ az ad sp create-for-rbac --name "myApp" --role contributor \
5695
"tenantId": "<GUID>",
5796
(...)
5897
}
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'
59126
```
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.
61127
62128
# Contributing
63129

0 commit comments

Comments
 (0)