1

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.

Avishay Cohen
  • 1,978
  • 2
  • 21
  • 34

1 Answers1

1

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/.....

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • thanks, i'll read on the link you added. is it possible to keep the ability to run both manually build package like i do now, and add on top of that building through the pipeline? or the pom can only describe a single flow? – Avishay Cohen Nov 06 '19 at 09:16
  • @AvishayCohen. Some of tasks we provide a input box that the customer could specified which directory they want this task executed on. Like this: https://imgur.com/a/0AQtkYg. This can let you customized the build directory. **BUT**, this input box does not applied in Maven task, which means there's no where you can add manually in task configuration, and need to change your pom.xml configuration to achieve this special path structure. – Mengdi Liang Nov 06 '19 at 09:30
  • i think i found a possible solution using mavenOptions, but when i try to add more then 1 option, the pipeline always fail on: `Unrecognized option: ` and it doesn't matter which option i try, same options as i use in my IntelliJ IDEA to build (which works) tried '-e', '-Dmaven.test.skip=true' and '-Pazure-pipeline` all result in error. how do i allow multiple values for mavenOption? in the doc there is always just 1 option which is the default: `mavenOptions: '-Xmx3072m'` – Avishay Cohen Nov 06 '19 at 13:11
  • @AvishayCohen, To use multi options, just leave space between options is ok. Like `-e -Pazure-pipeline`. But not sure the one you mentioned `-Pazure-pipeline`. I can know that `Dmaven.test.skip` is used to skip the test. Do you mind tell me how the `-Pazure-pipeline` means? – Mengdi Liang Nov 06 '19 at 15:03
  • I used this solution as a possible one for myself: https://stackoverflow.com/questions/3908013/maven-how-to-change-path-to-target-directory-from-command-line/12598554 adding a profile to the pom.xml – Avishay Cohen Nov 06 '19 at 15:09
  • @AvishayCohen. Great! Hope can hear good news if modifying the build directory in pom.xml could make you succeed for Maven task. Feel free to let me know if need any assistance:-) – Mengdi Liang Nov 06 '19 at 15:11
  • running this in the .yml file `mavenOptions: '-Pazure-pipeline -Dmaven.test.skip=true -e -X'` yields the same error, `Unrecognized option: -Pazure-pipeline` this same command works and compiles locally. do you have any idea why it is not valid in ADO pipeline? – Avishay Cohen Nov 06 '19 at 15:16
  • @AvishayCohen. I have not know much about the option `-Pazure-pipeline`. As the error said, this should not recognized in VSTS server but I can not sure. Could you tell me more about this option? Then I could possible to reproduce on my side and check our backend log to achieve more details. – Mengdi Liang Nov 06 '19 at 15:19
  • @AvishayCohen Hi, how’s things going now? Can you build successfully by applying adding directory in Pom.xml now? Did you still facing any issue? – Mengdi Liang Nov 12 '19 at 15:47