1

I would like to generate a password inside of the bash task. I came up with the following:

- task: Bash@3
    displayName: 'Bash generate password'
    inputs:
      targetType: 'inline'
      script: |
        password=$(cat /dev/urandom | tr -dc 'A-Za-z0-9_!@#$%^&*()\-+=' | fold -w 32 | head -n 1)

        echo "##vso[task.setvariable variable=password]$password"

Unfortunately this seems to be not working, cause the task is running forever. The agent is Linux machine.

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
mibrl12
  • 454
  • 5
  • 21

2 Answers2

4

This worked:

password=$(cat /dev/urandom | tr -dc 'A-Za-z0-9_!@#$%^&*()\-+=' | head -c24)

mibrl12
  • 454
  • 5
  • 21
  • Really thanks for sharing your solution here, if so, would you please accept your solution as the answer? So it would be helpful for other members who get the same issue to find the solution easily. Have a nice day:) – Jack Zhai Nov 13 '19 at 05:12
1

I know that this is an old thread, but this way if you set the pipeline variable "System.Debug" you can see the password printed in the pipeline Log.

The solution proposed by @mibrl12 can be improved adding issecret=true in the echo expression, as stated in the official documentation:

- task: Bash@3
  displayName: 'Bash generate password'
  inputs:
    targetType: 'inline'
    script: |
      password=$(cat /dev/urandom | tr -dc 'A-Za-z0-9_!@#$%^&*()\-+=' | head -c24)
      echo "##vso[task.setvariable variable=password;issecret=true]$password"

Hope it may helps.

ElettroAle
  • 119
  • 1
  • 8