0

I have a python script that creates a jenkins job, as below

def create_jenkins_job(self):
    jenk = jenkins.Jenkins(jenkins_url, username=jenkins_user, password=jenkins_token)

    jobs = jenk.create_job('test2', jenkins.EMPTY_CONFIG_XML)
    return True

This successfully creates an empty job as expected. I'm trying to have this job run an Ansible playbook, held locally in the same directory. The ansible plugin is already installed on the jenkins instance. Is it possible to create a job with the ansible parameter and pass the playbook to it?

CEamonn
  • 714
  • 8
  • 27
  • You would do that inside the `Jenkinsfile` associated with the job that your Python script is invoking. Documentation exists for that. – Matt Schuchard Dec 13 '18 at 15:17

1 Answers1

0

as per my understanding you want to do two things:

  1. create a job which is having ansible plugin build step.
  2. run the job passing(uploading) a local playbook and run the job using ansible plugin

if it is the case, then here is my answer: 1:

I know creating a sample job and copying it is not a good solution but it would work. But jobs = jenk.create_job('test2', jenkins.EMPTY_CONFIG_XML) is going to create an empty job which wont be having any pre-configuration. So we need some configuration(any existing job's config.xml) to pre-configure the job using python-jenkins api.

ameydev
  • 76
  • 1
  • 6