How to build a multiline shell text script on stage on the yaml file to perform it on azure VM

Galgani, Stefano 205 Reputation points
2024-01-08T14:04:48.4933333+00:00

Hi community,

I'm building a github action to upload jar file on Azure linux VM.
I'm using az vm run-command invoke command ( link ) to perform download jar file on the Azure linux VM.

My piece of bash text script in the stage is the followed:

      - name: Bash commands
        shell: bash
        run: |
          # Script to deploy app      
          az vm run-command invoke -g ${{ secrets.AZURE_RG }} -n ${{vars.VIRTUAL_MACHINE_ID_02}} --command-id RunShellScript --scripts 'cd /tmp && curl -O -J -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $1" -H "X-GitHub-Api-Version: 2022-11-28" $2' --parameters ${{secrets.GIT_CICD_TOKEN}} ${{env.ARTIFACT_URL}}

As you can see before of the curl download command I have concatenated another command inline with && and the script is working fine as below:

--scripts 'cd /tmp && curl -O -J -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $1" -H "X-GitHub-Api-Version: 2022-11-28" $2'

Could you tell me the right syntax to have a script commands multiline in the stage to be performed by Azure agent present in Azure VM ?

Thanks

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,015 questions
0 comments No comments
{count} votes

Accepted answer
  1. kobulloc-MSFT 26,801 Reputation points Microsoft Employee Moderator
    2024-01-08T17:27:44.5233333+00:00

    Hello, @Galgani, Stefano ! Let me know in the comments if I'm missing something but there are two special characters you can use for multiline commands depending on the environment.

    How do I create multiline shell scripts with Azure commands?

    When entering multi-line commands, you'll use "\" for Bash and "`" for PowerShell. Since this is Bash, you'll use "\" before starting a new line.

    Edit: Specific to GitHub Actions, you may need to use > (Folded Block Scalar) which converts new lines into spaces.


    I hope this has been helpful! Your feedback is important so please take a moment to accept answers.

    If you still have questions, please let us know what is needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    User's image


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.