Setting Maven params in Jenkins

前端 未结 1 1189
无人及你
无人及你 2020-12-06 10:36

I am experimenting the Jenkins, and am looking for a way to allow Jenkins to set parameters for different project builds. Normally all these attributes are stored in the set

1条回答
  •  南方客
    南方客 (楼主)
    2020-12-06 11:09

    There are some options for you. Here's what I'm using:

    Create profiles in your build.

    
        
            
                findbugs-exclude.xml
            
        
        
            
                
                    org.codehaus.mojo
                    findbugs-maven-plugin
                    
                        findbugs-exclude.xml
                    
                
            
        
    
    
        package
        
            
                
                    org.apache.maven.plugins
                    maven-dependency-plugin
                    
                        
                            copy-dependencies
                            package
                            
                                copy-dependencies
                            
                            
                                ${project.build.directory}/lib
                                false
                                false
                                true
                                runtime
                            
                        
                    
                
            
        
    
    

    The you can define in jenkins clean install -P package - for package task or clean install for normal build

    Put parameters directly to pom from command line:

    Maven call:

    mvn clean install -Dparameter.one=ONE -Dparameter.two=TWO
    

    POM:

    
        4.0.0
        com.test
        test
        1.0.0
        test
        
            6.4
        
    
        
            
                org.testng
                testng
                ${testng.version}
                test
            
        
    
    

    If you run it normally testng version 6.4 will be used. But if you run it like: mvn clean install -Dtestng.version=6.3.1 testng version 6.3.1 will be used.

    See

    Downloading: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.pom Downloaded: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.pom (0 B at 0.0 KB/sec) Downloading: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.jar Downloaded: http://repo.maven.apache.org/maven2/org/testng/testng/6.3.1/testng-6.3.1.jar (0 B at 0.0 KB/sec)

    You can parametrize default part of pom (setting default values directly and overriding it by execution properties)

    Finally you can use environment variables Parameterized Build or Parameterized Trigger Plugin

    Change in last example version:

    
        org.testng
        testng
        ${env.testngVersion}
        test
    
    

    In bash you can call:

    export testngVersion=6.0
    mvn clean install
    

    Or in jenkins by setting testngVersion=6.0 in This build is parameterized section

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