簡體   English   中英

如何在 azure 管道中使用的 windows-latest 代理上使用 postgres db?

[英]How to use the postgres db on the windows-latest agent used in the azure pipeline?

I have a java maven project that I am building with an azure pipeline with as host "windows-latest" as it contains the correct java 13 version. 但是,對於集成測試,我需要一個 postgres 數據庫,並且“windows-latest”代理包含一個 postgres 數據庫,請參閱: link 但是我該如何使用它呢? 我嘗試通過在 Maven 任務中包含它的 serviceName 作為服務來使用它:

services:
   postgres: postgresql-x64-13

但是后來我收到錯誤消息,它找不到該名稱的服務。 我嘗試通過 env 設置定義 db 屬性(參見下面的 yml),然后它顯示錯誤:

Caused by: java.net.ConnectException: Connection refused

我還嘗試通過我在開發過程中使用的項目根目錄中的 docker-compose.yml 通過腳本任務運行它,但是 docker-compose 拋出一個錯誤,說它找不到 compose 文件,我也懷疑這是正確的方法。

那么我可以在 windows 代理上使用 postgres 數據庫嗎? 如何?

我的 azure 管道片段:

    variables:
    MAVEN_CACHE_FOLDER: $(Pipeline.Workspace)/.m2/repository
    MAVEN_OPTS: "-Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)"
    application_name: clearsky
    service_name: backend
    mygetUsername: myserUsername
    mygetPassword: mytoken
    SPRING_DATASOURCE_URL: jdbc:postgresql://localhost:5432/postgres
    SPRING_DATASOURCE_USER: postgres
    SPRING_DATASOURCE_PASSWORD: root

stages:
    - stage: create_artifact
      displayName: Create artifact
      jobs:
          - job: build
            displayName: Build, test and publish artifact
            steps:
                - task: Maven@3
                  name: maven_package
                  displayName: Maven package
                  inputs:
                      goals: "package"
                      mavenPomFile: "backend/pom.xml"
                      options: '--settings backend/.mvn/settings.xml -DmygetUsername=$(mygetUsername) -DmygetPassword=$(mygetPassword)'
                      mavenOptions: "-Xmx3072m $(MAVEN_OPTS)"
                      javaHomeOption: "JDKVersion"
                      jdkVersionOption: "1.13"
                      mavenAuthenticateFeed: true

在 Azure Devops Windows 代中,默認情況下禁用/停止 postgresql。

這是配置文檔

Property    Value
ServiceName postgresql-x64-13
Version 13.2
ServiceStatus   Stopped
ServiceStartType    Disabled

您可以嘗試以下命令來啟動 postgresql。

"C:\Program Files\PostgreSQL\13\bin\pg_ctl.exe" start -D "C:\Program Files\PostgreSQL\13\data" -w

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM