Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jenkins_job module fails creating jobs of type OrganizationFolder #18995

Closed
tumbl3w33d opened this issue Dec 8, 2016 · 7 comments
Closed

jenkins_job module fails creating jobs of type OrganizationFolder #18995

tumbl3w33d opened this issue Dec 8, 2016 · 7 comments
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module.

Comments

@tumbl3w33d
Copy link
Contributor

ISSUE TYPE
  • Bug Report
COMPONENT NAME

jenkins_job

ANSIBLE VERSION
ansible 2.3.0 (devel a236cbf3b4) last updated 2016/12/08 13:23:10 (GMT +200)
CONFIGURATION

N/A

OS / ENVIRONMENT

N/A

SUMMARY

The jenkins_job module cannot handle creating jobs of type jenkins.branch.OrganizationFolder.

Background:
If we use the plugins

  • bitbucket
  • cloudbees-bitbucket-branch-source

to integrate with Bitbucket, then there's the option to create a kind of wrapper job that only has the purpose of scanning Bitbucket projects for repositories (and therein a 'Jenkinsfile'). Something similar exists for GitHub and possibly other providers.

If we use the jenkins_job to create such a wrapper job it fails, because it cannot determine whether this job is disabled or not. The JSON response for such job doesn't include the 'color' attribute which the module looks for and there is in general no option for disabling such job apart from disabling its polling.

TL;DR:
The module does

def get_job_status(self):
    try:
        return self.server.get_job_info(self.name)['color'].encode('utf-8')
    except Exception:
        e = get_exception()
        self.module.fail_json(msg='Unable to fetch job information, %s' % str(e))

and throws this exception because there is no color attribute in the response.

The good news - the rest of the module just works if you hack around this check like

def get_job_status(self):
    return "enabled"

Now my suggestion is to make the module ignore this check for this kind of job.

STEPS TO REPRODUCE

An example job template which I created for a generic job role can be found here:
https://gist.github.com/tumbl3w33d/a1a986fa73da6adc0078532a5578782a

This should allow you to choose the right identifiers for such kind of wrapper jobs, so you could skip the failing check.

An example of a JSON response of the jenkins api for such a wrapper job:
https://gist.github.com/tumbl3w33d/04379f013e1e58dff13da60d46234975

EXPECTED RESULTS

The wrapper job gets created.

ACTUAL RESULTS
fatal: [targethost]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to fetch job information, 'color'"}

I'd be happy to support you with testing a possible pull request because it's quite hard for you to reproduce this setup.

@ansibot ansibot added module This issue/PR relates to a module. plugin affects_2.3 This issue/PR affects Ansible v2.3 labels Dec 13, 2016
@ansibot
Copy link
Contributor

ansibot commented Dec 19, 2016

@sermilrod
Copy link
Contributor

Hi @tumbl3w33d sorry for the delay but I got notified very recently. I will take a look a it.

I will try to reproduce it and once I get the same failure I will work on a long term solution for this.

Thank you very much for your patience.

@sermilrod
Copy link
Contributor

Hi @tumbl3w33d I have been testing it and I have reached to a point of good working of the module.

The result of the execution of the module as a proof of concept is here:
https://gist.github.com/sermilrod/454193198ff833b49dba3f1a04b83179

At code level, I skip enabled/disabled validation in those jobs(identified by _class property) in which it does not make sense to have a state of enabled/disabled.

If you are happy with this approach and the results shown in the gist, I will open a PR in ansible-extra-modules repo.

Best regards.

@tumbl3w33d
Copy link
Contributor Author

LGTM @sermilrod and thank you for maintaining this module.

Btw.: did you create that PR in the extra module repo on purpose? From my understanding this is part of the main repo now. Hope it will not get lost over there.

@sermilrod
Copy link
Contributor

It was not on purpose, it was my mistake. When I developed the module I had to submit the code to ansible-extra-module repo but apparently this has changed. The PR is updated here #19644

@jimi-c jimi-c removed the plugin label Jan 4, 2017
@abadger
Copy link
Contributor

abadger commented Jan 4, 2017

PR has been mergedto devel. Closing issue ticket.

@mdelapenya
Copy link

mdelapenya commented Jun 13, 2017

Hey @sermilrod it happens the same with Blue Ocean pipeline jobs.

This is the snippet generated by Jenkins when creating a Pipeline:

<org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject plugin="workflow-multibranch@2.15">

Thanks!

@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. module This issue/PR relates to a module.
Projects
None yet
Development

No branches or pull requests

6 participants