Is there a way to keep Hudson / Jenkins configuration files in source control?

后端 未结 10 802
难免孤独
难免孤独 2020-11-29 15:45

I am new to Hudson / Jenkins and was wondering if there is a way to check in Hudson\'s configuration files to source control.

Ideally I want to be able to click some

相关标签:
10条回答
  • 2020-11-29 16:11

    I checked in hudson entirely, you could use this as a starting point https://github.com/morkeleb/continuous-delivery-with-hudson

    There are benefits to keeping entire hudson in git. All config changes are logged and you can test the testup quite easily on one machine and then update the other machine(s) using git pull.

    We used this as a boilerplate for our hudson continuous delivery setup at work.

    Regards Morten

    0 讨论(0)
  • 2020-11-29 16:13

    You can find configuration files in Jenkins home folder (e.g. /var/lib/jenkins).

    To keep them in VCS, first login as Jenkins (sudo su - jenkins) and create its git credentials:

    git config --global user.name "Jenkins"
    git config --global user.email "jenkins@example.com"
    

    Then initialize, add and commit the basic files such as:

    git init
    git add config.xml jobs/ .gitconfig
    git commit -m'Adds Jenkins config files' -a
    

    also consider creating .gitignore with the following files to ignore (customize as needed):

    # Git untracked files to ignore.
    
    # Cache.
    .cache/
    
    # Fingerprint records.
    fingerprints/
    
    # Working directories.
    workspace/
    
    # Secret files.
    secrets/
    secret.*
    *.enc
    *.key
    users/
    id_rsa
    
    # Plugins.
    plugins/
    
    # State files.
    *.state
    
    # Job state files.
    builds/
    lastStable
    lastSuccessful
    nextBuildNumber
    
    # Updates.
    updates/
    
    # Hidden files.
    .*
    # Except git config files.
    !.git*
    !.ssh/
    
    # User content.
    userContent/
    
    # Log files.
    logs/
    *.log
    
    # Miscellaneous litter
    *.tmp
    *.old
    *.bak
    *.jar
    *.json
    *.lastExecVersion
    

    Then add it: git add .gitignore.

    When done, you can add job config files, e.g.

    shopt -s globstar
    git add **/config.xml
    git commit -m'Added job config files' -a
    

    Finally add and commit any other files if needed, then push it to the remote repository where you want to keep the config files.


    When Jenkins files are updated, you need to reload them (Reload Configuration from Disk) or run reload-configuration from Jenkins CLI.

    0 讨论(0)
  • 2020-11-29 16:17

    The way I prefer is to exclude everything in the Jenkins home folder except the configuration files you really want to be in your VCS. Here is the .gitignore file I use:

    *
    !.gitignore
    !/jobs/*/*.xml
    !/*.xml
    !/users/*/config.xml
    !*/
    

    This ignores everything (*) except (!) .gitignore itself, the jobs/projects, the plugin and other important and user configuration files.

    It's also worth considering to include the plugins folder. Annoyingly updated plugins should be included...

    Basically this solution makes it easier for future Jenkins/Hudson updates because new files aren't automatically in scope. You just get on the screeen what you really want.

    0 讨论(0)
  • 2020-11-29 16:20

    To manually manage your configuration with Git, the following .gitignore file may be helpful.

    # Miscellaneous Hudson litter
    *.log
    *.tmp
    *.old
    *.bak
    *.jar
    *.json
    
    # Generated Hudson state
    /.owner
    /secret.key
    /queue.xml
    /fingerprints/
    /shelvedProjects/
    /updates/
    
    # Tools that Hudson manages
    /tools/
    
    # Extracted plugins
    /plugins/*/
    
    # Job state
    builds/
    workspace/
    lastStable
    lastSuccessful
    nextBuildNumber
    

    See this GitHub Gist and this blog post for more details.

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