Python/Jenkins

From Omnia
Jump to navigation Jump to search

Jenkins

See Jenkins

pip

Wrong:

pip install jenkins
error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27

Correct:

pip install python-jenkins

Python Plugin

"Python Plugin" - Adds the ability to execute python scripts as build steps. - https://wiki.jenkins-ci.org/display/JENKINS/Python+Plugin

Add node environment variable (node properties):

name=PYTHONUNBUFFERED
value=1

Jenkins Python API

pip install python-jenkins

http://python-jenkins.readthedocs.io/en/latest/

"""  Jenkins Python API Utilities."""
import argparse
import datetime
import glob
import json
import multiprocessing
import os
import pdb
import re
import subprocess
import sys
import tempfile
import time
import urllib3
from copy import deepcopy
from operator import itemgetter

import jenkins
from jira import JIRA

urllib3.disable_warnings()


# Jenkins Python API Utilities.
if __name__ == '__main__':

   # Get user parameters.
    parser = argparse.ArgumentParser(description="Jenkins")
    parser.add_argument('--jenkins-user', metavar='USER', type=str, default="jenkins",
                        help='The Jenkins user ID.')
    parser.add_argument('--jenkins-password', metavar='PASSWORD', type=str, default="password",
                        help='The Jenkins password.')
    parser.add_argument('--jenkins-url', metavar='URL', type=str, default="https://jenkins.oeey.com:8443",
                        help='The Jenkins URL.')
    args = parser.parse_args()

   # Set up jenkins.
    jenkins_server = jenkins.Jenkins(args.jenkins_url, username=args.jenkins_user, password=args.jenkins_password)

   # Delete server nodes.
    nodes = jenkins_server.get_nodes()
    for node in nodes:
        #print node
        # delete nodes with "old-" in name
        if "old-" in node["name"]:
            print "Deleting node:  {}".format(node["name"])
            jenkins_server.delete_node(node["name"])