简体   繁体   中英

Jenkins job with different maven versions

I have a maven Jenkins job, that is part of a multijob. Τhis used to run always on windows nodes, but currently we have created some linux nodes, too, that we want to utilize. The thing is that inside the job,at build step you have to choose:

在此处输入图片说明

This maven version applies when building the job. For example the maven version that applied here,, is linked to the path were maven is installed for windows. So this path, is applicable only for windows nodes, therefore, the job cannot be run by a linux node. Is there a workaround for this? thanks!

You can achieve it using Jenkins pipeline. Just set two maven config in Jenkins > global tool configuration. One for windows maven and other for linux.

node {
def mvnHome
stage('Build') {
    // Run the maven build
    if (isUnix()) {
        mvnHome = tool 'Maven-linux'
        sh "'${mvnHome}/bin/mvn' clean package "
    } else {
        mvnHome = tool 'Maven-windows'
        bat(/"${mvnHome}\bin\mvn" clean package /)
    }
}

Another way to do it is to use Jenkins Conditional build step plugin .

  • Create freestyle job
  • In Build Step select conditional step single or multiple.
  • In the Run? you can select execute shell
  • In Builder select invoke-top-level-maven-target and select maven-linux in maven version. Then you can configure maven goals and other steps
  • In Build Step on again select conditional step single or multiple.
  • In the Run? you can select execute windows batch command
  • In Builder select invoke-top-level-maven-target and select maven-window in maven version. Then you can configure maven goals and other steps

Jenkins Job设置上述步骤。

Configure your linux slaves:

  • Manage jenkins > manage nodes > %node > configure > Node properties
  • Then specify mvn and java located on your slave and fill in Tool ocations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM