我創建了一個 Azure 管道,它應該使用 GCP 服務帳戶進行身份驗證并執行 maven 測驗步驟。在測驗中,我有一個 BigQuery 客戶端直接連接到 BigQuery 資料集,對其進行查詢并進行一些斷言,這就是我需要憑據的原因。
在我的本地機器上一切正常,我在那里GOOGLE_APPLICATION_CREDENTIALS
指向.json
包含服務帳戶密鑰。
即使在管道中,除了 maven 命令外,一切都可以正常使用密鑰(我已經在一些 terraform 步驟上對其進行了檢查,并且他們正在獲取以這種方式提供的憑據)。
下面是我正在使用的代碼:
Azure 管道:
steps:
- task: Bash@3
displayName: Copy GCP Service Account Key
inputs:
workingDirectory: ${{parameters.working_drectory}}
targetType: 'inline'
script: 'echo ${{parameters.credentials}} | base64 -d > svc.json'
- task: laurensknoll.google-cloud-sdk-tasks.gcloud-runner.GcloudRunner@0
displayName: 'gcloud auth activate-service-account'
inputs:
command: 'auth activate-service-account'
arguments: '--key-file svc.json'
workingDirectory: ${{parameters.working_drectory}}
- task: laurensknoll.google-cloud-sdk-tasks.gcloud-runner.GcloudRunner@0
displayName: 'gcloud config set project'
inputs:
command: 'config set project'
arguments: ${{parameters.project}}
workingDirectory: ${{parameters.working_drectory}}
- task: MavenAuthenticate@0
# This task will authenticate your maven feed for input deps and output deps
inputs:
artifactsFeeds: $(incomingFeedName)
- task: Maven@3
# The version in the POM has to be set to the 'correct value' which is defined by line 2 of this file
# Note that this changes the pom, so the cache key in the step called 'Cache Maven' will change, and we will need to change this back later
inputs:
mavenPomFile: 'samples/testproject/pom.xml'
goals: 'test'
mavenAuthenticateFeed: true
displayName: Build test and set the version, package
相關的POM部分:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<parallel>all</parallel>
<threadCount>4</threadCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<systemPropertyVariables>
<WSNSHELL_HOME>GOOGLE_APPLICATION_CREDENTIALS</WSNSHELL_HOME>
</systemPropertyVariables>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${maven-surefire-plugin.version}</version>
</dependency>
</dependencies>
</plugin>
我已經嘗試過以及將GOOGLE_APPLICATION_CREDENTIALS
作為選項傳遞給 maven ,-DGOOGLE_APPLICATION_CREDENTIALS=svc.json
但這也沒有奏效
uj5u.com熱心網友回復:
問題是 Maven 作業目錄中不存在憑據 json 檔案,這意味著 Maven 作業目錄和其他步驟作業目錄不一樣。
該問題已通過將憑證 json 檔案復制到 Maven 作業目錄來解決。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/440903.html
上一篇:無法從父級決議junit