Avishay Cohen
Avishay Cohen

Reputation: 2208

setting up a maven pipeline for a sub directory in a single-repository in Azure Repo git

We started to work with ADOgit repo. As part of the move we would like to build some projects directly in ado - as a first effort we decided to create a pipeline for a standard Java Server that is built with maven.

working on ubuntu/windows we compile fine using the following command:mvn package -Dmaven.test.skip=true -e -X as the the new git repo in ado is a single repo for multiple projects, the java project, called "ContentResolver" is not the root of the repo but a sub dir.

as such, i have modified the .yml file as follow:

# Build your Java project and run tests with Apache Maven.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/java

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: Maven@3
  inputs:
    mavenPomFile: 'ContentResolver/pom.xml'
    mavenOptions: '-Dmaven.test.skip=true'
    javaHomeOption: 'JDKVersion'
    jdkVersionOption: '1.7'
    jdkArchitectureOption: 'x64'
    publishJUnitResults: true
    testResultsFiles: '**/surefire-reports/TEST-*.xml'
    goals: 'package'

which is pretty much what the yml file they give you, excpet i change the lines:

mavenPomFile: 'ContentResolver/pom.xml' to be relative

and mavenOptions: '-Dmaven.test.skip=true' becuase for now the ADO do not recognize -e -X but i will fix this later.

and the paths from the log itself:

Failed to read schema document 'file:/home/vsts/work/1/s/src/main/resources/model.xsd'

/home/vsts/work/1/s/src/main/resources/configuration.xsd (No such file or directory)

which means i need to change some other variable to point the maven to look for model and configuraiton in ContentResolver/src/... instead of directly in src.

i have not found such a way. i tried to change to following:

$(Agent.BuildDirectory)=ContentResolver

$(Agent.WorkFolder)=ContentResolver

$(Build.SourcesDirectory)=ContentResolver

but none of those helped me.

Upvotes: 1

Views: 3752

Answers (1)

Mengdi Liang
Mengdi Liang

Reputation: 18958

Agent.BuildDirectory, Agent.WorkFolder, Build.SourcesDirectory

These variables which represent the working directory, are all system pre-defined variable. They can not be modified or override. In another word, even you try to assign them a new value, ti will not work since they are read-only:

enter image description here

That's why they are all not work for you.


According to your special scenario, I think just the configuration of Azure Devops could not achieve that. Because the directory of .xsd does not decided by Azure Devops, it only depends on what your pom.xml defined. For pipeline, all of them working directory is s folder.

In one word, for pipeline server, the .xsd looking path structured like this:

Azure Devops working directory + Pom.xml build directory

Here you need consider do something to pom.xml.

As this doc said:

Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/test/java; and so on. When executing a task or goal, Maven looks for the POM in the current directory.

If you want its looking path is in ContentResolver/src/..., at least, you need change your default directory in pom.xml. For, how to change your pom.xml configuration, you can refer to this thread.

Only after you change the directory in pom.xml, then relative to the VSTS server, it can locate the path to ../../s/ContentResolver/src/.....

Upvotes: 1

Related Questions