简体   繁体   中英

Deploying two different versions of same jars through jenkings on different servers

I have two servers for my java application and I'm using jenkins to deploy my code on those servers. The application is same but because of the nature of work we are doing we need different versions of same custom jars on each server.

1: I've tried to set environment variables and tried to get artifact and group Id's of those in pom.xml but we can not access environment variables in pom.xml

2: I've tried changing their names and import both jars but that's insane one of them is ignored and both the servers use only one version.

I've been struggling with it for a long time now, The only possible solution that comes to my mind is that i create two different git repositories and make different jenkin jobs for every server.

Can anyone help me figure out how can I import different versions on different servers, that'd mean a lot. Thanks in advance.

If I get you correctly,

different versions of some custom jars

are different version of yours dependencies. This can be easily achieved using maven profiles. Your pom.xml would look similair to this (XML is simplified to minimum.

 <project>
   <!-- Basic info like model,  artifact, group etc. -->
   <dependencies>
      <!-- Your usual deps as you are used to -->
   </dependencies>
   <profiles>
     <profile>
         <id>profile1</id>
         <dependencies>
              <!-- Extra deps for this profile -->
         </dependencies>
     </profile>
     <profile>
         <id>profile2</id>
         <dependencies>
              <!-- Extra deps for this profile -->
         </dependencies>
     </profile>
   </profiles>
 </project>

IDEs commonly provides way to set profile, so devs should not have problem . From jenkins, are while building from command line you would be invoking command with given profile. You can have separate jobs or you can create your job with parameters.

mvn install -P profile1

Alternatively, profile can be activated by enviroment variable . Problem may be that this variable must be availble during compilation.

Another aproach would be branching your code for different customers as Abhilas mentioned in comment.

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