Skip to main content

A lemniscat plugin to run azurecli scripts

Project description

lemniscat.plugin.azurecli

A plugin to operate Azure services through Azure cli into a lemniscat workflow

Description

This plugin allows you to operate Azure services through Azure cli into a lemniscat manifest.

Usage

Pre-requisites

In order to use this plugin, you need to have an Azure subscription and an Azure service principal. You can create a service principal using the Azure CLI, PowerShell, or the Azure portal. The service principal is used to authenticate the Azure CLI to your Azure subscription.

After that you to be sure that you have the Azure CLI installed on your agent. You can install it using the following command:

Linux

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Windows

Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'

You need also set environment variables to authenticate the Azure CLI to your Azure subscription.

  • ARM_SUBSCRIPTION_ID : The subscription ID that you want to use
  • ARM_CLIENT_ID : The client ID of the service principal
  • ARM_CLIENT_SECRET : The client secret of the service principal
  • ARM_TENANT_ID : The tenant ID of the service principal

You need to add plugin into the required section of your manifest file.

requirements:
  - name: lemniscat.plugin.azurecli
    version: 0.1.0.9

Running powershell commands with Azure CLI

- task: azurecli
  displayName: 'Azure CLI'
  steps:
    - run
  parameters:
    scripttype: pwsh
    commandtype: inline
    script: |
      $version = az --version
      Write-Host "Azure CLI version: $version"

Running powershell script with Azure CLI

- task: azurecli
  displayName: 'Azure CLI'
  steps:
    - run
  parameters:
    scripttype: pwsh
    commandtype: file
    filePath: ${{ workingdirectory }}/scripts/ClearAzureContainer.ps1
    fileParams:
      storageAccountName: ${{ storageAccountName }}
      containerName: ${{ containerName }}

Running powershell commmands and pass variables through json file

[!NOTE] This feature is particulary recommand when you need to manipulate complexe variable with your task. You can access to the variables in the json file by using the following command:

$location = Get-Location
$variables = Get-Content "$($location.path)/vars.json" | ConvertFrom-Json -Depth 100
- task: azurecli
  displayName: 'Azure CLI'
  steps:
    - run
  parameters:
    scripttype: pwsh
    commandtype: inline
    script: |
      $location = Get-Location
      $variables = Get-Content "$($location.path)/vars.json" | ConvertFrom-Json -Depth 100
      $version = az --version
      Write-Host "Azure CLI version: $version"
    storeVariablesInFile:
      format: json
      withSecrets: false

Inputs

Parameters

  • scripttype: The type of the script to run. It can be only pwsh (for the moment)
  • commandtype: The type of the command to run. It can be inline or file
  • script: The script to run. It can be a powershell command line. It is used only if commandtype is inline
  • filePath: The path of the powershell script file (*.ps1) to run. It is used only if commandtype is file
  • fileParams: The parameters to pass to the powershell script file. It is used only if commandtype is file
  • storeVariablesInFile: Describe the way to store the variables in a file to used in the task.

StoreVariablesInFile

  • format: The format of the file to store the variables. It can be json or yaml
  • withSecrets: A boolean value to indicate if the secrets should be stored in the file. It can be true or false

Outputs

You can push variables to the lemniscat runtime in order to be used after by other tasks. To do that, you need to use Write-Host command in your powershell script to push variables to the lemniscat runtime. You must use the following format to push variables to the lemniscat runtime: [lemniscat.pushvar] <variableName>=<variableValue>

For example:

Write-Host "[lemniscat.pushvar] workspaceExist=$workspaceExist"

You can specify the sensitivity of the variable by adding secret like this : [lemniscat.pushvar.secret] <variableName>=<variableValue>

For example:

Write-Host "[lemniscat.pushvar.secret] storageAccountKey=$storageAccountKey"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lemniscat_plugin_azurecli-0.3.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lemniscat.plugin.azurecli-0.3.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file lemniscat_plugin_azurecli-0.3.0.tar.gz.

File metadata

File hashes

Hashes for lemniscat_plugin_azurecli-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a7c43ab0ea8016e408826508816fea56608559e01facf681ffac584cb643984d
MD5 1896bdc399dddaed4ea18f82554f0601
BLAKE2b-256 47446bc735a169312d29730244775e99d5aadf9b7184daf405f912477b4d1fe4

See more details on using hashes here.

File details

Details for the file lemniscat.plugin.azurecli-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lemniscat.plugin.azurecli-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbeeea4c73d272b8f088398919a724233ade4488c06c12ffac75799244b37db4
MD5 34d2ae42262e87e7006e4bc2f3bc84b6
BLAKE2b-256 b55990f6340c88be7e680b7b135cf2c268f38d73a445629c62987d465f6f4d7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page