How to manage a common ant build script across multiple project build jobs on jenkins?

后端 未结 3 2082
你的背包
你的背包 2020-12-01 15:35

I have a set of java projects coming from different git repositories which I want to be built with Jenkins.

All of them share the same ant build script, which employ

3条回答
  •  孤街浪徒
    2020-12-01 16:11

    Not an uncommon problem as @whiskeyspider states it's not confined to Jenkins. In my opinion it's also one of the issues that holds backs large legacy ANT builds. Over time it gets harder and harder to change the common logic due to a justifiable fear that it breaks dependent builds.

    Keeping the common logic in a separate repository or a git submodule is sound advice because it enables version control of this logic. Another option is to package the common logic as an ANT lib

    
    
        
            
                 
            
        
    
        ..
        ..
    
        
            
        
    

    While it appears more complicated I maintain creating these kinds of common tasks makes for a more reusable and readable build file. It also makes it obvious what your organisation's customisations are. I find it especially useful for hiding implementation details that might involve nasty embedded scripts.

    Finally I'm a big fan of using ivy for managing my 3rd party dependencies. This means I can easily download whatever version of the common logic my build needs from my repository.

    How to create an ANT lib

    ├── build.xml
    └── src
        └── com
            └── example
                └── commonbuild
                    └── antlib.xml
    

    antlib.xml

    
        
            
            
            
            
                
                
                
            
        
    
    

    Note:

    • This example has a single task. In reality your common build logic would provide multiple macrodefs.

    build.xml

    Just jar up the XML file:

    
        
    
    

    My build logic additionally would publish this jar file into my repository, so that other builds can pull it down using ivy. Also means that the common build logic can have a separate and formal release management life-cycle (Very important in a large organisation)

提交回复
热议问题