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

后端 未结 10 801
难免孤独
难免孤独 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 15:58

    I've written a plugin that lets you check your Jenkins instructions into source control. Just add a .jenkins.yml file with the contents:

    script:
        - make
        - make test
    

    and Jenkins will do it:

    enter image description here

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

    There is a new SCM Sync Configuration plug-in which does exactly what you are looking for.

    SCM Sync Configuration Hudson plugin is aimed at 2 main features :

    • Keep sync'ed your config.xml (and other ressources) hudson files with a SCM repository
    • Track changes (and author) made on every file with commit messages

    I haven't actually tried this yet, but it looks promising.

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

    A more accurate .gitignore, inspired by the reply from nepa:

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

    It ignores everything except for .xml config files and .gitignore itself. (the difference to nepa's .gitignore is that it doesn't "unignore" all top-level directories (!*/) like logs/, cache/, etc.)

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

    Most helpful Answer

    There is a plugin called SCM Sync configuration plugin.


    Original Answer

    Have a look at my answer to a similar question. The basic idea is to use the filesystem-scm-plugin to detect changes to the xml-files. Your second part would be committing the changes to SVN.

    EDIT: If you find a way to determine the user for a change, let us know.

    EDIT 2011-01-10 Meanwhile there is a new plugin: SCM Sync configuration plugin. Currently it only works with subversion and git, but support for more repositories is planned. I am using it since version 0.0.3 and it worked good so far.

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

    Answer from Mark (https://stackoverflow.com/a/4066654/142207) should work for SVN and Git (although Git configuration did not work for me).

    But if you need it to work with Mercurial repo, create a job with following script:

    hg remove -A || true
    hg add ../../config.xml
    hg add ../../*/config.xml
    if [ ! -z "`hg status -admrn`" ]; then
        hg commit -m "Scheduled commit" -u fill_in_the@blank.com
        hg push
    fi
    
    0 讨论(0)
  • 2020-11-29 16:09

    Note that Vogella has a recent (January 2014, compared to the OP's question January 2010) and different take on this.
    Consider that the SCM Sync configuration plugin can generate a lot of commits.
    So, instead of relying on a plugin and an automated process, he manages the same feature manually:

    Storing the Job information of Jenkins in Git

    I found the amount of commits a bit overwhelming, so I decided to control the commits manually and to save only the Job information and not the Jenkins configuration.
    For this switch into your Jenkins jobs directory (Ubuntu: /var/lib/jenkins/jobs) and perform the “git init” command.

    I created the following .gitignore file to store only the Git jobs information:

    builds/
    workspace/
    lastStable
    lastSuccessful
    nextBuildNumber
    modules/
    *.log
    

    Now you can add and commit changes at your own will.
    And if you add another remote to your Git repository you can push your configuration to another server.

    Alberto actually recommend to add as well (in $JENKINS_HOME):

    • jenkins own config (config.xml),
    • the jenkins plugins configs (hudson*.xml) and
    • the users configs (users/*/config.xml)
    0 讨论(0)
提交回复
热议问题