I want to pass PAT as pipeline parameter to script(gitlab.sh) that calls Gitlab REST API:
gitlab.sh
#!/bin/bash
set -e
MY_PAT="${MY_PAT}" #I want this to be secret and not printed in logs
function rest_api {
curl -sSL -H "Content-Type: application/json" -H "PRIVATE-TOKEN:$MY_PAT" -X POST
--data '{"name": "my-group","path": "my-group"}'
https://gitlab.example.com/api/v4/groups
}
rest_api
azure-pipelines.yml
pool:
vmImage: 'ubuntu-latest'
parameters:
- name: myPAT
displayName: 'My PAT'
type: string
steps:
- checkout: self
- script: |
echo "Creating group in Gitlab"
export MY_PAT=${{parameters.myPAT}} #how can I pass this secretly to gitlab.sh
bash -x gitlab.sh
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/heads/feature'))
displayName: 'Creating group in Gitlab'