0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Pipelines にて異なるジョブ間で変数を利用する場合には dependsOn が必要

Last updated at Posted at 2022-09-12

概要

Azure Pipelines にて異なるジョブ間で変数を利用する場合には dependsOn が必要となるようです。

下記のようなジョブをもつパイプラインを実行する場合に、変数を定義している①のジョブに直接依存関係がある③にて①で定義した変数を利用でき、依存関係がない④では①で定義した変数を利用できませんでした。

image.png

下記のように、明示的に変数を定義している(set_var)に対してdependsOnの指定をする必要があります。

- job: can_get_variable
  dependsOn:
    - server_task
    - set_var
  variables:
    SET_VAR: $[ dependencies.set_var.outputs['set_var.MyVar'] ]
  steps:
  - checkout: none
  - task: CmdLine@2
    displayName: Execute Databricks Workflow of test
    inputs:
      script: |
        echo $(SET_VAR)

詳細

実行 YAML

jobs:
- job: set_var
  steps:
  - checkout: none
  - task: CmdLine@2
    displayName: Execute Databricks Workflow of test
    name: set_var
    inputs:
      script: |
        echo "##vso[task.setvariable variable=MyVar;isOutput=true;]abc"
- job: server_task
  dependsOn: set_var
  pool: Server
  steps:
  - task: Delay@1
    displayName: 'Delay'
    inputs:
      delayForMinutes: 0
- job: can_get_variable
  dependsOn:
    - server_task
    - set_var
  variables:
    SET_VAR: $[ dependencies.set_var.outputs['set_var.MyVar'] ]
  steps:
  - checkout: none
  - task: CmdLine@2
    displayName: Execute Databricks Workflow of test
    inputs:
      script: |
        echo $(SET_VAR)
- job: can_not_get_variable
  dependsOn:
    - server_task
    # - set_var
  variables:
    SET_VAR: $[ dependencies.set_var.outputs['set_var.MyVar'] ]
  steps:
  - checkout: none
  - task: CmdLine@2
    displayName: Execute Databricks Workflow of test
    inputs:
      script: |
        echo $(SET_VAR)

set_varの実行結果

image.png

server_taskの実行結果

image.png

can_get_variableの実行結果

echo で呼び出すことができている。

image.png

can_not_get_variableの実行結果

echo で呼び出すことができていない。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?