Is there any way to change the working directory of a Jenkins Maven build?

前端 未结 9 1810
半阙折子戏
半阙折子戏 2020-12-14 16:13

Is there any way to change the working directory of a Jenkins Maven build?

Use Case

There is a Maven build that will only work if the current working direc

相关标签:
9条回答
  • 2020-12-14 16:47

    Not sure when this was added, but for the Jenkins in front of me (Jenkins ver. 1.627 per the bottom of the page), there's now an option for defining where the root pom.xml is (help message says:

    If your workspace has the top-level pom.xml in somewhere other than the 1st module's root directory, specify the path (relative to the module root) here, such as parent/pom.xml. If left empty, defaults to pom.xml

    ). I was facing the same issue but then realized the answer was staring me in the face (note that I did not have to hit advanced as Hua2308 suggested, probably because they changed the UI)

    0 讨论(0)
  • 2020-12-14 16:47

    You can use Maven's -f option

    -f,--file <arg>    Force the use of an alternate POM file (or directory with pom.xml).
    

    For example if your project has a structure:

    README.md
    sources
    |----pom.xml
    |----services
    |    |----pom.xml
    |    +----src
    |----webservices
    |    |----pom.xml
    |    +----src
    +----....
    useful
    docs
    

    then you can use Goals in Invoke top-level Maven targets:

    -f sources/pom.xml clean install
    
    0 讨论(0)
  • 2020-12-14 16:50

    Solution:

    cd subfolder; mvn -f ../pom.xml task
    

    Maven does not provide an option to do it the other way round, meaning the sensible way for this use-case, probably because Maven hates you.

    0 讨论(0)
提交回复
热议问题