1

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. However, for the integration tests, I need a postgres db and the "windows-latest" agent contains a postgres db, see: link. But how can I use this? I tried to use it by including it's serviceName in the Maven task as service:

services:
   postgres: postgresql-x64-13

But then I get the error it can not find a service by that name. I tried defining the db properties through env settings (see yml below), and then it shows the error:

Caused by: java.net.ConnectException: Connection refused

I also tried running it through a script task through the docker-compose.yml in the root of the project that I use during development, but docker-compose throws an error saying it can't find the compose file, I also doubt this the correct way.

So can I use the postgres db on the windows agent? and how?

My azure pipeline snippet:

    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
edbras
  • 4,145
  • 9
  • 41
  • 78
  • Hi @edbras. Have you tried to hardcode the username and password in your java maven project? for example: `spring.datasource.username=postgres spring.datasource.password=root `In this case, will you get the same error? – Kevin Lu-MSFT Mar 08 '21 at 09:20
  • 1
    I don't know, I have just switch to Ubuntu image to get that working. But why should that be different then defining it in the variable section? – edbras Mar 10 '21 at 07:15
  • Thanks for your info. The difference between windows and ubuntu agent is that the postgresql is disabled/stop by default in windows agent. – Kevin Lu-MSFT Mar 10 '21 at 08:04
  • 2
    You could try the following command to start the postgresql and check if it could work. `"C:\Program Files\PostgreSQL\13\bin\pg_ctl.exe" start -D "C:\Program Files\PostgreSQL\13\data" -w` – Kevin Lu-MSFT Mar 10 '21 at 08:05
  • Ohh, cool @KevinLu-MSFT, I will try that in the next days and let you know if it works – edbras Mar 11 '21 at 07:48
  • Feel free to let me know the result. I will still be here to help you. – Kevin Lu-MSFT Mar 11 '21 at 07:58
  • Hi @edbras. Is there any update about this ticket? Feel free to let me know if the script could solve this issue. Just a remind of [this](https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – Kevin Lu-MSFT Mar 16 '21 at 08:37
  • @KevinLu-MSFT: yes, thanks, I used marked your answer as the correct solution as it works fine – edbras Mar 17 '21 at 10:00

1 Answers1

2

In Azure Devops Windows agen, the postgresql is disabled/stop by default.

Here is the configuration doc.

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

You could try the following command to start the postgresql.

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

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28