Create a job for Jenkins using Python

Source: Internet
Author: User

Purpose: Dynamically create the job of Jenkins by invoking Jenkins's command

How to use, using Python scripts, more APIs can go to the official website to view, http://jenkinsapi.readthedocs.io/en/latest/

Using Python to call Jenkinsapi, you first need to install the package, installation method

1. Installation
Pip Install Jenkinsapi

After the installation is complete, check to see if the installation is successful, import the package for viewing,

From Jenkinsapi.jenkins Import Jenkins

If the installation is not successful, the import will prompt an error

Installation succeeds without prompting for errors

1. Role

Create the job principle, is to use existing projects for project replication, each Jenkins job is actually an XML file, just need to copy the configuration file, the project name changes, you can generate a new job

The XML configuration file for the original project is

From __future__ import print_functionfrom jenkinsapi.jenkins import jenkinsimport sysimport timereload (SYS) Sys.setdefaultencoding (' utf8 ') Jenkins_url = ' Access to Jenkins ' domain address/jenkins/' jenkins_user = ' Jenkins login admin ' jenkins_ Password = ' Jenkins login password ' def creater_job (job_name):    ss = Jenkins (Jenkins_url,jenkins_user,jenkins_password)    copy_job_name = ' job1 ' #jenkins的job    xml = Ss[copy_job_name].get_config ()  #获取配置文件    job = Ss.create_job (job_name, XML) if __name__== ' __main__ ':    creater_job ("June")

The generated job

Create a job for Jenkins using Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.