简体   繁体   English

Jenkins作业使用不同的Maven版本

[英]Jenkins job with different maven versions

I have a maven Jenkins job, that is part of a multijob. 我有一个行家詹金斯(Jenkins)工作,这是多工的一部分。 Τhis used to run always on windows nodes, but currently we have created some linux nodes, too, that we want to utilize. 他曾经总是在Windows节点上运行,但是目前我们也创建了一些Linux节点,希望使用。 The thing is that inside the job,at build step you have to choose: 问题是在工作内部,在构建步骤中您必须选择:

在此处输入图片说明

This maven version applies when building the job. 该Maven版本在构建作业时适用。 For example the maven version that applied here,, is linked to the path were maven is installed for windows. 例如,此处应用的maven版本链接到为Windows安装了maven的路径。 So this path, is applicable only for windows nodes, therefore, the job cannot be run by a linux node. 因此,此路径仅适用于Windows节点,因此,该作业无法由linux节点运行。 Is there a workaround for this? 有没有解决方法? thanks! 谢谢!

You can achieve it using Jenkins pipeline. 您可以使用Jenkins管道来实现。 Just set two maven config in Jenkins > global tool configuration. 只需在Jenkins>全局工具配置中设置两个Maven配置。 One for windows maven and other for linux. 一个用于Windows Maven,另一个用于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 . 另一种方法是使用Jenkins 条件构建步骤插件

  • 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. 在Builder中,选择invoke-top-level-maven-target,然后选择maven版本的maven-linux。 Then you can configure maven goals and other steps 然后,您可以配置Maven目标和其他步骤
  • In Build Step on again select conditional step single or multiple. 再次在Build Step on上选择单个或多个条件步骤。
  • In the Run? 在逃跑? you can select execute windows batch command 您可以选择执行Windows批处理命令
  • In Builder select invoke-top-level-maven-target and select maven-window in maven version. 在Builder中,选择invoke-top-level-maven-target,然后选择maven版本的maven-window。 Then you can configure maven goals and other steps 然后,您可以配置Maven目标和其他步骤

Jenkins Job设置上述步骤。

Configure your linux slaves: 配置您的Linux从站:

  • Manage jenkins > manage nodes > %node > configure > Node properties 管理詹金斯>管理节点>%node>配置>节点属性
  • Then specify mvn and java located on your slave and fill in Tool ocations 然后指定位于您的从属服务器上的mvn和java并填写工具位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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