stash-jenkins-postreceive-webhook icon indicating copy to clipboard operation
stash-jenkins-postreceive-webhook copied to clipboard

Allow global default configuration

Open kuhnroyal opened this issue 12 years ago • 12 comments
trafficstars

Allow the hook to be configured globally with the ability to override the global configuration for each repository.

kuhnroyal avatar Apr 26 '13 12:04 kuhnroyal

+1 to this. I just had to change the port that Jenkins was running on and had to edit about 50 repos by hand to update the configuration.

Is having a global Jenkins url possible? Without knowing much about Stash plugins, is this even possible?

mveitas avatar Feb 20 '14 20:02 mveitas

Wow! I bet that wasn't fun. Sorry about that. I'm sure it is possible, seeing that other plugins do it. I'm still learning new stuff about plugin development, so will just need to learn how to do so.

I'll take a look at it here in the near future and will see what I can do. May be a little bit before a solution is in place.

mikesir87 avatar Feb 20 '14 20:02 mikesir87

No need to be sorry about that. I had to do it by hand since I don't have access to the Stash server, otherwise I would have gone in and see if I could do some replacement in the config files.

I might take a peek at it as well if I can find some time.

mveitas avatar Feb 20 '14 20:02 mveitas

+1 We have hundreds of repositories and configuring per repo basis is painful.

astromatt avatar Feb 27 '14 08:02 astromatt

So... I've done some playing around with making a global configuration page and at least see how to pull it off.

But, question from you all... what settings would be useful at a global level? All of them? Just a subset? Might there be any other settings you'd find useful?

I'm also thinking about the ability of allowing a repository to trigger multiple notifications to multiple instances. Have to figure out how that plugs in to this too...

mikesir87 avatar Feb 27 '14 23:02 mikesir87

The perfect thing would be a list (one or more) Jenkins instances and a default protocol (ssh) setting.

So after this configuration, there will be nothing to set per repository, unless you'd like to override the default settings (like using a testing Jenkins instance for this particular repo, etc)

astromatt avatar Feb 28 '14 06:02 astromatt

Ok. Sounds great.

As an fyi... each repository will still require the webhook to be manually turned on. I haven't seen anything that let's me build support for a "this hook is enabled on all repos". But, I don't think that's a huge problem as it's a one-time knob when creating the repo.

mikesir87 avatar Feb 28 '14 14:02 mikesir87

True, that's won't be a problem.Thanks a lot, you're great! :} Matt

On Fri, Feb 28, 2014 at 3:07 PM, Michael Irwin [email protected] wrote:

Ok. Sounds great.

As an fyi... each repository will still require the webhook to be manually turned on. I haven't seen anything that let's me build support for a "this hook is enabled on all repos". But, I don't think that's a huge problem as it's a one-time knob when creating the repo.

Reply to this email directly or view it on GitHub: https://github.com/Nerdwin15/stash-jenkins-postreceive-webhook/issues/5#issuecomment-36353199

astromatt avatar Feb 28 '14 15:02 astromatt

I would appreciate this as we have an ever growing number of repos and each one currently needs a manual config.

Every one of our repos uses the same Jenkins URL and the repos clone URL.

ericlong avatar Feb 24 '15 15:02 ericlong

In my case, I update them using a fabric file, and python-jenkins / stashy modules for python

It will grab a | separated list of jobs, remove their polling at jenkins, grab its repository, and enable stash jenkins hook with proper configuration.


@task
def update_joblist(jenkins_url, user, password, joblist, stash_password):
    joblist2 = joblist.split('|')

    for job in joblist2:
        update_all_single(jenkins_url, user, password, job, stash_password)


@task
def update_all_single(jenkins_url, user, password, jobname, stash_password):
    server = jenkins2.Jenkins(jenkins_url, user, password)
    xml = server.get_job_config(jobname)
    xml_instance = ET.fromstring(server.get_job_config(jobname))
    triggers = xml_instance.find('triggers')
    gitconfig = xml_instance.find('.//hudson.plugins.git.UserRemoteConfig')
    if gitconfig is not None:
        #So if the project is using git, go ahead
        print("Updating %s job" % jobname)
        if triggers is not None:
            scmtrigger = triggers.find('hudson.triggers.SCMTrigger')
            if scmtrigger is not None:
                specs = scmtrigger.find('spec')
                if specs is not None:
                    specs.text = ""
                else:
                    spec = ET.Element("spec")
                    scmtrigger.append(spec)

            if scmtrigger is None:
                newel = ET.Element("hudson.triggers.SCMTrigger")
                pch = ET.Element("ignorePostCommitHooks")
                pch.text = 'false'
                spec = ET.Element("spec")
                newel.append(pch)
                newel.append(spec)
                triggers.append(newel)

            repo = xml_instance.find('.//hudson.plugins.git.UserRemoteConfig')
            repourl = repo.find('url')
            spliturl = repourl.text.split('/')
            reponame = spliturl[-1].rstrip('git').rstrip('.')
            projname = spliturl[-2]

            newxmlstring = ET.tostring(xml_instance)
            server.reconfig_job(jobname, newxmlstring)

            update_single_repo(projname, reponame, user, stash_password,
                               repourl.text)

@task
def update_single_repo(projname, reponame, stash_user, stash_pwd, sshurl):

    stash = stashy.connect("yourjenkinsurl", stash_user,
                           stash_pwd)
    repohook = stash.projects[projname].repos[reponame].settings.hooks[
        'com.nerdwin15.stash-stash-webhook-jenkins:jenkinsPostReceiveHook']

    config = {"jenkinsBase": "yourjenkinsurl",
              "gitRepoUrl": sshurl, "ignoreCerts": 'true',
              "omitHashCode": 'true',
              "ignoreCommitters": "", "branchOptions": "",
              "branchOptionsBranches": ""}
    repohook.configure(config)
    repohook.enable()

ahharu avatar Mar 05 '15 09:03 ahharu

+1 on @ahharu . All Stash plugins can be configured automatically. And the more generic use case of automating the plugin config is the way to go. Global makes sense when the server is only for one division/team building Jenkins. But we have 6 teams with 3 different Jenkins setups. So we found it was worth our while to automate hooks per repo generically, and this plugin came along with it.

carpnick avatar Sep 11 '15 23:09 carpnick

You find an example on how to only inherit one global repository url in https://github.com/digital-wonderland/stash-plugins-jenkins/blob/master/src/main/java/com/atlassian/stash/plugins/jenkins/JenkinsBuildTrigger.java#L52. Maybe we can at least start with just one global repository URL which can be overwritten for each repository. Afterwards one may still finetune that.

kwin avatar Jan 10 '16 11:01 kwin