Install and configure the Chef adapter to associate with Jenkins.
Chef prerequisites |
Jenkins host prerequisites |
- Chef Development Kit version: 0.10.0
- chef-client version: 12.5.1
- berks version: 4.0.1
- kitchen version: 1.4.2
- Server access to the host running Chef with sufficient
privileges to modify Chef files
|
- Python version: 2.7
- pychef version: 0.2.3, or later
- "root" privileges on the host running Jenkins
|
- Assumptions
-
- Administrator with strong command of Chef
- A functioning Chef environment
- Chef is used in the actual deployment of software (for example,
deploying a jar/war/ear or an rpm to the intended target)
- Jenkins CI job that creates the Binary artifact to be deployed
by Chef is up and running, and integrated with the
CollabNet TeamForge instance
Add Chef deployment as a tool in TeamForge project
-
In TeamForge, go to the Project Admin page of the
project for which you wish to integrate this Chef deployment scenario.
-
Select Tools from the left pane.
-
Click Add Tool.
-
Select Other for SELECT TOOL TYPE option.
-
Select the Include Traceability check box.
-
Select Custom Activity Source for "Source Type".
-
Select the desired Jenkins/Build source in the Associated
Source field.
-
Finish any other confirmation, then click SHOW
CONFIGURATION before saving the configuration. Copy all
configuration parameters to a text file for use in later steps.
Configuring Chef
-
Add the following code to your deployment cookbook’s
metadata.rb file.
depends 'teamforge-associations', '~> 0.1.0'
-
Add the following code to your recipes/default.rb file of
your deployment cookbook.
include_recipe 'teamforge-associations::alldetails'
-
Edit your deployment recipe to notify the TeamForge Orchestrate reporting
recipe when it is run. This can be done by adding the following code to your
deployment resource.
notifies :enable, 'chef_handler[CustomHandler::AllDetails]'
-
Edit your attributes/default.rb file or any other
attributes file that you are using for this recipe and add the following
attributes.
default['teamforge-associations']['alldetails']['data_bag'] = 'traceability_parameters'
Note: This parameter denotes the data bag name on the Chef Server that has
been written by Jenkins.
default['teamforge-associations']['alldetails']['ctf_url'] = <CTF URL>
default['teamforge-associations']['alldetails']['ctf_user'] = <CTF USER>
Note: This user must have rights to get/post schema on Orchestrate.
default[‘teamforge-associations’]['alldetails']['orc_server'] = '<ORC QUEUE SERVER>'
default['teamforge-associations’]['alldetails']['orc_user'] = '<QUEUE USERNAME>'
default['teamforge-associations']['alldetails']['orc_src_assoc_key'] = ‘<SOURCE ASSOCIATION KEY>’
default['teamforge-associations']['alldetails']['orc_queue_name'] = 'orchestrate.custom'
default['teamforge-associations']['passwords']['secret_path'] = '<PATH TO SECRET KEY>'
Note: This parameter contains the generic path on each node to the
encryption key that has been used to encrypt the Orchestrate password
that resides on the Chef server as an encrypted data bag.
-
Create a data bag named "passwords" on the Chef server and add two encrypted
data bag items named 'ctf_password' and 'orc_password' containing the encrypted
CTF password for the user set in
default['teamforge-associations']['alldetails']['ctf_user']
and the Orchestrate password for the user set up in
default['teamforge-associations’]['alldetails']['orc_user']
respectively.
The
passwords must be contained in a field named “password” in their respective data
bags. Please see http://docs.chef.io for information on using data
bags.
-
Once all changes are in place, upload the cookbook to the server. Any nodes
that this cookbook is assigned to will automatically pick up these changes when
they run chef-client next. If you wish to assign it to any
new nodes, follow the usual procedure to bootstrap the node and assign this
cookbook to its runlist.
Configuring Jenkins
To create an association between a Jenkins
build and a Chef deployment, the Chef deployment must be made aware of the
"current"' build number. To achieve this, Jenkins must be configured to create a
data bag on the Chef server and write its build number to the data bag item.
Please follow these instructions:
-
Install Python version 2 on the host running
Jenkins, if it is not already present. Please note that the expected version is
python2 (i.e., 2.7.x).
-
On the Jenkins server, install the python library 'pychef',
version 0.2.3 or later. Pychef is a tool needed for Jenkins to communicate with
and operate on Chef. Installing
Pychef
can usually be achieved with
the
following commands:
- sudo easy_install pip
- sudo pip install pychef
-
Verify Pychef installation.
-
Enter python from the command line
interface.
-
Enter import chef at the Python prompt.
-
If “import chef” is without any errors, Pychef installation is
successful. Enter CTRL+D to exit the Python
shell.
-
If there are errors about missing “libcrypto.so”, you must install the
openssl developer package for your OS. Once installed, verify Pychef
installation again.
-
Download the scripts to write/update from Jenkins to Chef DataBag from the
Orchestrate community site. The
contents are a directory named “pychef” with two scripts inside it namely
“data_bag” and “set_jenkins_data_bag.py”.
-
Login into the shell of the Jenkins server as the user “jenkins”.
-
Enter “cd” to make sure you are in the home directory.
-
Copy the “pychef” directory and it’s contents downloaded in step 17 into the home
directory.
-
Copy the “.chef” directory that is part of the starter kit into the pychef
directory. Add a build step in Jenkins, after the actual build takes place,
using option “execute command” and enter the following in the available text
area:
cd ${HOME}/pychef
./data_bag -b ${BUILD_NUMBER}
That concludes the Chef integration with TeamForge via Jenkins.
Test the integration by running through an entire cycle to ensure Orchestrate
receives the Chef deployment activity and also that the Chef deployment is
associating properly to the configured Jenkins build.