0
0

More than 1 year has passed since last update.

【Azure DevOps】Azure Pipelinesに設定したymlから環境変数的に値を参照したい

Posted at

はじめに

CICDのために欠かせないパイプライン
シークレットとして扱いたい文字列や、可変にしたい設定値などがよくある
ローカルマシンやサーバであれば環境変数として設定できるが、CIを動かしているAgentではどのように可変でプライベートな値を設定するのかを記載する

前提

LibraryにVariable groupsを作成

image.png

「+ Variable group」をクリック

Variablesを定義

image.png

  1. groupに名前をつける
  2. 環境変数として使用したい値をkey valueの形式で追加する

yamlに値を参照するための記述を追加

ci.yml
# variable groupから環境設定を読み込み
variables:
  - group: qiita-env

steps:
  - bash: echo $(Build.SourceBranch)
    displayName: 'echo working branch name'

  - script: |
      npm test
    displayName: 'unit test'
    env:
      SECRET: $(SECRET) # $(variable)の形式でLibraryに定義した値にアクセスできる

参照

余談

LibraryにアクセスできるPipelineを制限する

デフォルトだと、OrganizationかProjectか分からないが、ほぼ全てのPipelineがLibrary/Variable groupにアクセスできてしまう
セキュリティ向上のためにも、アクセスできるPipelineを限定しておくと良い

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0