Home > other >  Azure Pipelines - Equivalent Az DevOps Commands Required
Azure Pipelines - Equivalent Az DevOps Commands Required

Time:10-08

I have successfully used the below commands to update our Azure DevOps project wiki in Powershell ISE.

$etagVar = (az devops wiki page show --org https://dev.azure.com/[MyOrg] --project [MyProjectName] --path '/MyWiki/HelloWorld' --wiki [MyWiki_wiki] --query eTag -o tsv)

az devops wiki page update --path 'MyWikiPath/HelloWorld' --wiki [MyWiki_wiki --content "Yessssss, it worked !!!" --version $etagVar

I now need to incorporate these two commands into a YAML Azure Pipeline. I am not particularly bothered whether this is done using Bash, PowerShell, Windows Batch Script or any Azure pipeline Task for that matter. As long as it works, I have no qualms at all.

So far, I've tried a Bash task and it's been hugely unsuccessful. Any suggestions or ideas would therefore be most appreciated.

CodePudding user response:

You just run it with PowerShell like your run it in your PC, you just need to authenticate (with the env):

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      $etagVar = (az devops wiki page show --org https://dev.azure.com/shaykia --project GitSample --path '/README' --wiki 1 --query eTag -o tsv)
      az devops wiki page update --path 'MyWikiPath/HelloWorld' --wiki [MyWiki_wiki --content "Yessssss, it worked !!!" --version $etagVar
  env:
    AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

CodePudding user response:

I can get my Pipeline to update a Wiki using the Bash task. Here is my working YAML definition:

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- bash: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project=$(System.TeamProject) --use-git-aliases true
  displayName: 'Set default Azure DevOps organization and project'

- bash: |
    eTag=$(az devops wiki page show --wiki project.wiki --path '/MyWiki' --query eTag -o tsv)
    az devops wiki page update --wiki project.wiki --path '/MyWiki' --content "Hello World!" --version $eTag
  displayName: 'Update Wiki'
  env:
    AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

As for the auth, you can authenticate using the System.AccessToken security token used by the running pipeline, by assigning it to an environment variable named AZURE_DEVOPS_EXT_PAT, as shown in the snippet above. For other examples, check this article: Azure DevOps CLI in Azure Pipeline YAML

Note: You may have to tweak your pipeline permissions a bit to let it update the Wiki.

CodePudding user response:

That's excellent @Bhargavi Annadevara. On the back of my last post yesterday, I pondered briefly and realised that I'd perhaps even answered my own question by stating "......I am not particularly bothered whether this is done using Bash, Powershell, Windows Batch Script"

That's because I very quickly managed to revise my existing commands and implemented it with a Pipeline Powershell task (below) which achieved my objective.

- task: PowerShell@2
 inputs:
   targetType: 'inline'
   script: |
     # Write your PowerShell commands here.
           
     $etagVar = (az devops wiki page show --org https://dev.azure.com/[OrgName] --project [TeamProjectName] --path '/[TeamProjectWiki_Path]' --wiki [WikiName] --query eTag -o tsv)
     az devops wiki page update --path '[TeamProjectWiki_Path]' --wiki [WikiName] --content "Hello World....!!" --version $etagVar --verbose
 displayName: 'Preparing to update the wiki page'
 env:
   AZURE_DEVOPS_EXT_PAT: $(System.AccessToken)

It's good that we at least have two working options to go with. Will try your Bash implementation too by the way. Thanks.

  • Related