Setup Jenkins-job-builder on Windows

On my laptop (Windows 7), I tried to install Jenkins-job-builder for Jenkins.

Details about Jenkins-job-builder, http://ci.openstack.org/jenkins-job-builder/index.html

1. Download https://pypi.python.org/packages/source/j/jenkins-job-builder/jenkins-job-builder-0.3.0.tar.gz#md5=836d3c3279f906a634fe4c7956fa3a48 

2. Download Python-2.7.7.msi and install it.

3. Unzip and cd to the source dir. Run ‘python setup.py install’. It failed to run due to the following error,

C:\Users\luhuang>D:

D:\>cd jenkins-job-builder-0.3.0

D:\jenkins-job-builder-0.3.0>python setup.py install
Traceback (most recent call last):
File “setup.py”, line 15, in <module>
import setuptools
ImportError: No module named setuptools

4. Install setuptools. Here I just download the .exe version of setuptools. https://pypi.python.org/pypi/setuptools#windows-7-or-graphical-install

5. Run ‘python setup.py install’. Here it fails again with a different error,

mimetypes.init() # try to read system mime.types
File “C:\Python27\lib\mimetypes.py”, line 348, in init
db.read_windows_registry()
File “C:\Python27\lib\mimetypes.py”, line 256, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
WindowsError: [Error 2] ???????????
Something went wrong during the installation.
See the error message above.

D:\jenkins-job-builder-0.3.0>

6. Hack into the code to fix this issue.

diff

diff2

The copy of the revised file, http://pan.baidu.com/s/1o6mH5bk

 def enum_types(mimedb):
 i = 0
 while True:
 try:
 ctype = _winreg.EnumKey(mimedb, i)
 except EnvironmentError:
 break
 try:
 ctype = ctype.encode(default_encoding) # omit in 3.x!
 except UnicodeEncodeError:
 pass
 else:
 yield ctype
 i += 1

 default_encoding = sys.getdefaultencoding()
 if default_encoding != 'gbk':
 reload(sys)
 sys.setdefaultencoding('gbk')
 default_encoding = 'gbk'
 with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
 for subkeyname in enum_types(hkcr):
 try:
 with _winreg.OpenKey(hkcr, subkeyname) as subkey:
 # Only check file extensions
 if not subkeyname.startswith("."):
 continue
 # raises EnvironmentError if no 'Content Type' value
 mimetype, datatype = _winreg.QueryValueEx(
 subkey, 'Content Type')
 if datatype != _winreg.REG_SZ:
 continue
 try:
 mimetype = mimetype.encode(default_encoding)
 subkeyname = subkeyname.encode(default_encoding)
 except UnicodeEncodeError:
 continue
 self.add_type(mimetype, subkeyname, strict)
 except EnvironmentError:
 continue

7. Run ‘python setup.py install’ again and it would still fail the same. https://issues.jenkins-ci.org/browse/JENKINS-14256

Installed c:\python27\lib\site-packages\jenkins_job_builder-0.3.0-py2.7.egg
Processing dependencies for jenkins-job-builder==0.3.0
Searching for python-jenkins
Reading https://pypi.python.org/simple/python-jenkins/
Download error on https://pypi.python.org/simple/python-jenkins/: timed out — S
ome packages may not be found!
Couldn’t find index page for ‘python-jenkins’ (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: timed out — Some packages ma
y not be found!
No local packages or download links found for python-jenkins
error: Could not find suitable distribution for Requirement.parse(‘python-jenkin
s’)

8. Setup the proxy and retry

Installed c:\python27\lib\site-packages\python_jenkins-0.2.1-py2.7.egg
Searching for PyYAML
Reading https://pypi.python.org/simple/PyYAML/
Best match: PyYAML 3.11
Downloading https://pypi.python.org/packages/2.7/P/PyYAML/PyYAML-3.11.win32-py2.
7.exe#md5=d75320c7a904731d6e27418e346a92e1
Processing PyYAML-3.11.win32-py2.7.exe
creating ‘c:\users\luhuang\appdata\local\temp\easy_install-wohho7\PyYAML-3.11-py
2.7-win32.egg’ and adding ‘c:\users\luhuang\appdata\local\temp\easy_install-wohh
o7\PyYAML-3.11-py2.7-win32.egg.tmp’ to it
Moving PyYAML-3.11-py2.7-win32.egg to c:\python27\lib\site-packages
Adding PyYAML 3.11 to easy-install.pth file

Installed c:\python27\lib\site-packages\pyyaml-3.11-py2.7-win32.egg
Finished processing dependencies for jenkins-job-builder==0.3.0

D:\jenkins-job-builder-0.3.0>

It looks Jenkins-Jobs-Builder is installed successfully on my local Windows 7. I should verify it tomorrow.