Azure Pipelines
You can use the Phase CLI to effortlessly inject or expose secret inside your CI pipelines or jobs.
Prerequisites
- Have signed up for the Phase Console and created an application.
PHASE_SERVICE_TOKEN.
If you are using a Self-Hosted instance of the Phase Console, you may supply
PHASE_HOST environment variable with your URL (https://<HOST>).
For detailed cli install options, please see: Installation
Setting PHASE_SERVICE_TOKEN:
- Go to Azure DevOps Dashboard.
- Select your project, and click on
Project Settings. - Under
Pipelines, selectService connections. - Add a new service connection of type
Environment Variableand setPHASE_SERVICE_TOKEN.
Example:
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: BuildAndPush
jobs:
- job: Prepare
steps:
- script: curl -fsSL https://pkg.phase.dev/install.sh | bash
displayName: 'Install phase-cli'
- script: |
echo "##vso[task.setvariable variable=DOCKERHUB_USERNAME;]$(phase secrets export --app "my application name" --env prod DOCKERHUB_USERNAME | cut -d '=' -f2)"
echo "##vso[task.setvariable variable=DOCKERHUB_TOKEN;]$(phase secrets export --app "my application name" --env prod DOCKERHUB_TOKEN | cut -d '=' -f2)"
displayName: 'Export and set environment variables'
- job: BuildAndPush
dependsOn: Prepare
steps:
- script: |
docker login -u $(DOCKERHUB_USERNAME) -p $(DOCKERHUB_TOKEN)
docker build -t my-image .
docker push my-image:latest
displayName: 'Build and Push Docker image'