Azure Build Pipeline で変数を使う方法のメモ。
変数を自前で定義する
Microsoft Docs – Define variables
もともと定義されている変数を使う
Microsoft Docs – Use predefined variables
WorkDirectoryとかはPrededined Variableです。
コード
ubuntu上で実行した時の環境チェック。
デフォルトでbashコマンドが実行できるみたい。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# Starter pipeline # Start with a minimal pipeline that you can customize to build and deploy your code. # Add steps that build, run tests, deploy, and more: # https://aka.ms/yaml trigger: - master pool: vmImage: 'ubuntu-latest' stages: - stage: Build variables: environment: Build jobs: - job: FirstJob steps: - bash: echo $(PipelineLevelVariable) # 自前で定義した変数 - bash: echo $(Build.BuildNumber) - bash: echo $(Build.SourceBranchName) - bash: echo $(Build.SourceDirectory) - bash: echo $(Build.ArtifactStagingDirectory) - bash: ls -R $(System.DefaultWorkingDirectory) - bash: java -version # デフォルトで環境が入ってる - bash: node --version # デフォルトで環境が入ってる - bash: python --version # デフォルトで環境が入ってる - bash: mvn -version # デフォルトで環境が入ってる |
実行結果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
Starting: Bash ============================================================================== Task : Bash Description : Run a Bash script on macOS, Linux, or Windows Version : 3.163.1 Author : Microsoft Corporation Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/bash ============================================================================== Generating script. Script contents: echo 20200419.1 ========================== Starting Command Output =========================== /bin/bash --noprofile --norc /home/vsts/work/_temp/6439b522-c52f-4f91-9d58-2f3714c1c39e.sh 20200419.1 /bin/bash --noprofile --norc /home/vsts/work/_temp/21e7c37e-591b-440d-8ff4-c5d83a099603.sh master /bin/bash --noprofile --norc /home/vsts/work/_temp/19b7190f-d2b7-4f15-8c5c-04aac8d7832d.sh /home/vsts/work/_temp/19b7190f-d2b7-4f15-8c5c-04aac8d7832d.sh: line 1: Build.SourceDirectory: command not found /bin/bash --noprofile --norc /home/vsts/work/_temp/fffc1841-10ae-45cc-90b2-f22288a01090.sh /home/vsts/work/1/a /home/vsts/work/1/s/src/main/java/com/in28minutes/microservices/currencyexchangeservice/util: environment /home/vsts/work/1/s/src/main/java/com/in28minutes/microservices/currencyexchangeservice/util/environment: EnvironmentConfigurationLogger.java InstanceInformationService.java /home/vsts/work/1/s/src/main/resources: application.properties data.sql /home/vsts/work/1/s/src/test: java /home/vsts/work/1/s/src/test/java: com /home/vsts/work/1/s/src/test/java/com: in28minutes /home/vsts/work/1/s/src/test/java/com/in28minutes: microservices /home/vsts/work/1/s/src/test/java/com/in28minutes/microservices: currencyexchangeservice /home/vsts/work/1/s/src/test/java/com/in28minutes/microservices/currencyexchangeservice: CurrencyExchangeServiceApplicationTests.java /bin/bash --noprofile --norc /home/vsts/work/_temp/1c1527d0-724c-42de-a52e-92bba3a0f5b6.sh openjdk version "1.8.0_242" OpenJDK Runtime Environment (Zulu 8.44.0.11-linux64)-Microsoft-Azure-restricted (build 1.8.0_242-b20) OpenJDK 64-Bit Server VM (Zulu 8.44.0.11-linux64)-Microsoft-Azure-restricted (build 25.242-b20, mixed mode) /bin/bash --noprofile --norc /home/vsts/work/_temp/cce9473e-7a6d-4b5b-ba9c-36fd1a501ef0.sh v12.16.1 /bin/bash --noprofile --norc /home/vsts/work/_temp/6cd0ed01-473f-4ef8-8849-5e72f26ec774.sh Python 2.7.17 /bin/bash --noprofile --norc /home/vsts/work/_temp/0952e747-2662-43c8-9b43-5bd885eeb037.sh Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Maven home: /usr/share/apache-maven-3.6.3 Java version: 1.8.0_242, vendor: Azul Systems, Inc., runtime: /usr/lib/jvm/zulu-8-azure-amd64/jre Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "5.0.0-1035-azure", arch: "amd64", family: "unix" |
何もしなくても環境は整ってた。
コメントを残す