jenkins-job-builder setup on mac

jenkins-job-builder setup on mac

During my work day I use jenkins-jobs a lot since we have a lot of jenkins jobs. Running this tool on Centos, works like a charm. Tried to setup on my MAC and I failed to run it. Got the following errors:

knesenko@knesenko-mbp:~$ jenkins-jobs 
Traceback (most recent call last):
  File "/usr/local/bin/jenkins-jobs", line 6, in 
    from jenkins_jobs.cmd import main
  File "/Library/Python/2.7/site-packages/jenkins_jobs/cmd.py", line 27, in 
    from jenkins_jobs.builder import Builder
  File "/Library/Python/2.7/site-packages/jenkins_jobs/builder.py", line 25, in 
    import jenkins
  File "/Library/Python/2.7/site-packages/jenkins/__init__.py", line 54, in 
    from six.moves.http_client import BadStatusLine
ImportError: No module named http_client

The issue is MAC trying to use the old six version:

knesenko@knesenko-mbp:~$ ipython
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import six

In [2]: six.__version__
Out[2]: '1.4.1'

The solution is to change the PYTHONPATH to use modules you installed from pip. Put the following line to ~/.bash_profile:

export PYTHONPATH="/Library/Python/2.7/site-packages"
knesenko@knesenko-mbp:~$ source .bash_profile 
knesenko@knesenko-mbp:~$ jenkins-jobs 
usage: jenkins-jobs [-h] [--conf CONF] [-l LOG_LEVEL] [--ignore-cache]
                    [--flush-cache] [--version] [--allow-empty-variables]
                    {test,delete-all,update,delete} ...
knesenko@knesenko-mbp:~$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import six
>>> six.__version__
'1.9.0'
>>> import sys
>>> sys.path
['', '/Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']

Jenkins Groovy Script Code Completion

jenkins groovy script code completion

Do you always remember all methods of all classes in Jenkins and its plugins ? I don’t and it was had for me to google everything.

In my example I am using IntelliJ. Create a new MVN project jenkinsgroovy and add at least jenkins-core and the plugins you need as dependency in the pom.xml.

Example of pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>jenkinsgroovy</groupId>
    <artifactId>jenkinsgroovy</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <repositories>
        <repository>
            <id>jenkins-releases</id>
            <url>http://repo.jenkins-ci.org/releases/</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.jenkins-ci.main</groupId>
            <artifactId>jenkins-core</artifactId>
            <version>1.626</version>
        </dependency>
        <dependency>
            <groupId>org.jenkins-ci.main</groupId>
            <artifactId>maven-plugin</artifactId>
            <version>2.9</version>
        </dependency>
    </dependencies>

</project>

To add a groovy sdk to the project, go to: File -> Project Structure -> SDKs