Skip to content

Commit

Permalink
Merge pull request #34 from rightscale-cookbooks/white_14_01_acu15064…
Browse files Browse the repository at this point in the history
…7_ci_build_merge_branch

Create two jobs for every repo, fix issue with the change branch not being tested
  • Loading branch information
arangamani committed Jan 29, 2014
2 parents c265be1 + 4e8c5ef commit d308e8a
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ suites:
git_project_description: Resource to create a visual marker in the Chef log based on a template
git_repo: git://github.com/rightscale-cookbooks/marker.git
git_project_url: https://github.com/rightscale-cookbooks/marker
pull_request_builder_enabled: true
config:
git_setup:
git_username: rightscale-cookbooks-jenkins
Expand Down Expand Up @@ -59,6 +60,7 @@ suites:
git_description: Resource to create a visual marker in the Chef log based on a template
git_repo: git://github.com/rightscale-cookbooks/marker.git
git_project_url: https://github.com/rightscale-cookbooks/marker
pull_request_builder_enabled: true
config:
git_setup:
username: rightscale-cookbooks-jenkins
Expand Down
3 changes: 2 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ Vagrant.configure('2') do |config|
'marker' => {
'git_description' => 'Resource to create a visual marker in the Chef log based on a template',
'git_repo' => 'git://github.com/rightscale-cookbooks/marker.git',
'git_project_url' => 'https://github.com/rightscale-cookbooks/marker'
'git_project_url' => 'https://github.com/rightscale-cookbooks/marker',
'pull_request_builder_enabled' => true
}
},
'config' => {
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'Apache 2.0'
description 'Installs/Configures rs-cookbooks_ci'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '0.2.1'
version '0.2.2'

supports "ubuntu"

Expand Down
35 changes: 29 additions & 6 deletions recipes/jenkins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,38 @@
# This uses the jenkins_job resource to create jobs using a template. For each job, it creates a temporary config
# file then populates it using a template (.erb) which is filled out with variables stored in attributes
# Initially the job doesn't do anything when it is defined (hence action :nothing). It only kicks off once it is
# notified by the template.
# notified by the template. We are creating two jobs for every repo we want to test. The first is testing pushes to
# master and the second is for monitoring pull requests. It only creates the second job if the boolean value,
# pull_request_builder_enabled, is set to true. This gives the option of having repos tracked and tested on master only
# or master and pull requests

node['rs-cookbooks_ci']['jenkins']['jobs'].each do |job_name, job_config|

jenkins_job job_name do
jenkins_job "#{job_name}_master" do
action :nothing
config "/tmp/#{job_name}.xml"
config "/tmp/#{job_name}_master.xml"
end

template "/tmp/#{job_name}.xml" do
source 'job_config.xml.erb'
template "/tmp/#{job_name}_master.xml" do
source 'job_config_master.xml.erb'
mode 0644
variables({
:git_description => job_config['git_description'],
:git_repo => job_config['git_repo'],
:git_project_url => job_config['git_project_url'],
})
notifies :update, "jenkins_job[#{job_name}_master]", :immediately
end


jenkins_job "#{job_name}_pr" do
action :nothing
config "/tmp/#{job_name}_pr.xml"
only_if { job_config['pull_request_builder_enabled'] }
end

template "/tmp/#{job_name}_pr.xml" do
source 'job_config_pr.xml.erb'
mode 0644
variables({
:git_description => job_config['git_description'],
Expand All @@ -56,11 +77,13 @@
# We want to make sure the admins list is added for each job
:job_admins_list => node['rs-cookbooks_ci']['jenkins']['config']['ghprb']['admins'].join(' ')
})
notifies :update, "jenkins_job[#{job_name}]", :immediately
notifies :update, "jenkins_job[#{job_name}_pr]", :immediately
only_if { job_config['pull_request_builder_enabled'] }
end

end


# Create Git credentials using a template and store it as a config file in the Jenkins root
template node['rs-cookbooks_ci']['jenkins']['config']['git_config']['config_file'] do
source 'git_config.xml.erb'
Expand Down
56 changes: 56 additions & 0 deletions templates/default/job_config_master.xml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version='1.0' encoding='UTF-8'?>
<project>
<actions/>
<description><%= @git_description =%></description>
<keepDependencies>false</keepDependencies>
<properties>
<com.coravy.hudson.plugins.github.GithubProjectProperty plugin="[email protected]">
<projectUrl><%= @git_project_url =%></projectUrl>
</com.coravy.hudson.plugins.github.GithubProjectProperty>
</properties>
<scm class="hudson.plugins.git.GitSCM" plugin="[email protected]">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<name></name>
<refspec></refspec>
<url><%= @git_repo %></url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions>
<hudson.plugins.git.extensions.impl.WipeWorkspace/>
</extensions>
</scm>
<canRoam>true</canRoam>
<disabled>false</disabled>
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
<triggers>
<com.cloudbees.jenkins.GitHubPushTrigger plugin="[email protected]">
<spec></spec>
</com.cloudbees.jenkins.GitHubPushTrigger>
</triggers>
<concurrentBuild>false</concurrentBuild>
<builders>
<hudson.tasks.Shell>
<command>bundle install --path .gems
bundle exec berks install
bundle exec strainer test</command>
</hudson.tasks.Shell>
</builders>
<publishers>
<com.cloudbees.jenkins.GitHubCommitNotifier plugin="[email protected]"/>
</publishers>
<buildWrappers>
<hudson.plugins.ansicolor.AnsiColorBuildWrapper plugin="[email protected]">
<colorMapName>xterm</colorMapName>
</hudson.plugins.ansicolor.AnsiColorBuildWrapper>
</buildWrappers>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,10 @@
<refspec>+refs/pull/*:refs/remotes/origin/pr/*</refspec>
<url><%= @git_repo %></url>
</hudson.plugins.git.UserRemoteConfig>
<hudson.plugins.git.UserRemoteConfig>
<name>origin/master</name>
<refspec> +refs/heads/master:refs/remotes/origin/master</refspec>
<url><%= @git_repo %></url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
<name>${sha1}</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
Expand Down
4 changes: 4 additions & 0 deletions test/integration/jenkins/bats/jenkins.bats
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@
grep "<oauthAccessToken>thisIsAFakeToken</oauthAccessToken>" /var/lib/jenkins/com.cloudbees.jenkins.GitHubPushTrigger.xml
}

@test "Check that the pull request jobs are building the correct spec branch" {
grep -E "<name>\\$\{sha1\}</name>" /var/lib/jenkins/jobs/marker_pr/config.xml
}

0 comments on commit d308e8a

Please sign in to comment.