require 'rexml/text'
module JenkinsWorkflow
class Build
attr_accessor :url
def initialize(url: nil)
@url = url
end
#
def create(depot_path: nil, credential: nil, job_name: nil, branch: nil,
mailto: nil, test_ubuntu12: nil, test_ubuntu14: nil,
test_centos6: nil)
workflow_script=<<-END.gsub(/^[ ]{8}/, '')
try {
node('master') {
p4sync depotPath: '#{depot_path}', credential: '#{credential}'
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|set -e
|gem install bundler
|echo 'installing bundle dependencies'
|bundle install
|cd helix_web_services && bundle install && cd ..
|cd helix_web_services_client && bundle install && cd ..
|rake clean
|rake test
|rm -rf pkg
|cd helix_web_services && BRANCH=main rake build_version && cd ..
|rake build
|rake all:doc
""".stripMargin()
archive 'pkg/helix-web-services.tgz, **/doc-output/, **/spec-output/'
}
node('build-omnibus-ubuntu12') {
unarchive mapping: ['**/helix-web-services.tgz': '.']
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|gem install bundler
|rm -rf helix-web-services*
|set -e
|tar xzf pkg/helix-web-services.tgz
|rm -rf pkg
|cd helix-web-services
|rake set_writable
|cd packaging/omnibus-helix-web-services
|bundle install --without development
|export BUILD_ID=`date +'%Y-%m-%d_%H-%M-%S'`
|omnibus build helix-web-services
""".stripMargin()
archive 'helix-web-services/packaging/omnibus-helix-web-services/pkg/helix-web-services*precise_amd64.deb'
}
node('test-omnibus-ubuntu12') {
sh """#!/bin/bash --login
|set -x
|sudo service nginx stop
|sudo service helix_web_services stop
|sudo userdel helixwebservices
|sudo rm -rf /opt/perforce/helix-web-services/home
|sudo dpkg -r helix-web-services perforce-server perforce-cli perforce-cli-base perforce-p4dctl perforce-server-base nginx nginx-common nginx-full
|sudo dpkg -P helix-web-services perforce-server perforce-cli perforce-cli-base perforce-p4dctl perforce-server-base nginx nginx-common nginx-full
|sudo rm -rf /var/lib/perforce
|sudo rm -rf /var/log/perforce
|sudo rm -rf /opt/perforce
|sudo rm -rf /etc/perforce/p4dctl.conf.d
|sudo rm -rf /var/tmp/helix-web-services*
|sudo rm -rf /var/tmp/apt*
|sudo rm -rf /tmp/helix-web-services*
|sudo rm -rf /etc/nginx
|rm -rf helix-web-services
""".stripMargin()
}
node('test-omnibus-ubuntu12') {
unarchive mapping: ['**/helix-web-services*precise_amd64.deb': '.']
sh """#!/bin/bash --login
|set -v
|set -e
|sudo dpkg -i helix-web-services/packaging/omnibus-helix-web-services/pkg/helix-web-services*precise_amd64.deb
|sudo /opt/perforce/helix-web-services/bin/hws_configure
|sudo service nginx start
|sudo service helix_web_services start
""".stripMargin()
}
node('master') {
unarchive mapping: ['**/helix-web-services.tgz': '.']
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|gem install bundler
|set -e
|echo 'installing bundle dependencies'
|bundle install
|cd helix_web_services && bundle install && cd ..
|cd helix_web_services_client && bundle install && cd ..
|set -x
|rake clean
|rake 'remotetest[#{test_ubuntu12}]'
|mv helix_web_services_client/spec-output/helix_web_services_client_specs.html helix_web_services_client/spec-output/helix_web_services_client_specs-ubuntu12.html
""".stripMargin()
archive '**/spec-output/'
}
node('build-omnibus-ubuntu14') {
unarchive mapping: ['**/helix-web-services.tgz': '.']
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|gem install bundler
|rm -rf helix-web-services*
|set -e
|tar xzf pkg/helix-web-services.tgz
|rm -rf pkg
|cd helix-web-services
|rake set_writable
|cd packaging/omnibus-helix-web-services
|bundle install --without development
|export BUILD_ID=`date +'%Y-%m-%d_%H-%M-%S'`
|omnibus build helix-web-services
""".stripMargin()
archive 'helix-web-services/packaging/omnibus-helix-web-services/pkg/helix-web-services*trusty_amd64.deb'
}
node('test-omnibus-ubuntu14') {
sh """#!/bin/bash --login
|set -x
|sudo service nginx stop
|sudo service helix_web_services stop
|sudo userdel helixwebservices
|sudo rm -rf /opt/perforce/helix-web-services/home
|sudo dpkg -r helix-web-services perforce-server perforce-cli perforce-cli-base perforce-p4dctl perforce-server-base nginx nginx-core nginx-common
|sudo dpkg -P helix-web-services perforce-server perforce-cli perforce-cli-base perforce-p4dctl perforce-server-base nginx nginx-core nginx-common
|sudo rm -rf /var/lib/perforce
|sudo rm -rf /var/log/perforce
|sudo rm -rf /opt/perforce
|sudo rm -rf /etc/perforce/p4dctl.conf.d
|sudo rm -rf /var/tmp/helix-web-services*
|sudo rm -rf /var/tmp/apt*
|sudo rm -rf /tmp/helix-web-services*
|sudo rm -rf /etc/nginx
|rm -rf helix-web-services
""".stripMargin()
}
node('test-omnibus-ubuntu14') {
unarchive mapping: ['**/helix-web-services*trusty_amd64.deb': '.']
sh """#!/bin/bash --login
|set -v
|set -e
|sudo dpkg -i helix-web-services/packaging/omnibus-helix-web-services/pkg/helix-web-services*trusty_amd64.deb
|sudo /opt/perforce/helix-web-services/bin/hws_configure
|sudo service helix_web_services start
|sudo service nginx start
|sudo service nginx stop
|sudo service nginx start
""".stripMargin()
}
node('master') {
unarchive mapping: ['**/helix-web-services.tgz': '.']
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|gem install bundler
|set -e
|echo 'installing bundle dependencies'
|bundle install
|cd helix_web_services && bundle install && cd ..
|cd helix_web_services_client && bundle install && cd ..
|set -x
|rake clean
|rake 'remotetest[#{test_ubuntu14}]'
|mv helix_web_services_client/spec-output/helix_web_services_client_specs.html helix_web_services_client/spec-output/helix_web_services_client_specs-ubuntu14.html
""".stripMargin()
archive '**/spec-output/'
}
node('build-omnibus-centos6') {
unarchive mapping: ['**/helix-web-services.tgz': '.']
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|gem install bundler
|rm -rf helix-web-services*
|set -e
|tar xzf pkg/helix-web-services.tgz
|rm -rf pkg
|cd helix-web-services
|rake set_writable
|cd packaging/omnibus-helix-web-services
|bundle install --without development
|export BUILD_ID=`date +'%Y-%m-%d_%H-%M-%S'`
|omnibus build helix-web-services
""".stripMargin()
archive 'helix-web-services/packaging/omnibus-helix-web-services/pkg/helix-web-services*rpm'
}
node('test-omnibus-centos6') {
sh """#!/bin/bash --login
|set -x
|sudo p4dctl stop helix-web-services
|sudo killall p4d
|sudo initctl stop nginx
|sudo initctl stop helix_web_services
|sudo userdel helixwebservices
|sudo rm -rf /opt/perforce/helix-web-services/home
|sudo rpm -e helix-web-services perforce-server perforce-cli perforce-cli-base perforce-p4dctl perforce-server-base nginx
|sudo rm -rf /var/lib/perforce
|sudo rm -rf /var/log/perforce
|sudo rm -rf /opt/perforce
|sudo rm -rf /etc/perforce/p4dctl.conf.d
|sudo rm -rf /var/tmp/helix-web-services*
|sudo rm -rf /var/tmp/yum
|sudo rm -rf /tmp/helix-web-services*
|sudo rm -rf /etc/nginx
|rm -rf helix-web-services
""".stripMargin()
}
node('test-omnibus-centos6') {
unarchive mapping: ['**/helix-web-services*.rpm': '.']
sh """#!/bin/bash --login
|set -v
|set -e
|sudo rpm -i helix-web-services/packaging/omnibus-helix-web-services/pkg/helix-web-services*.rpm
|sudo /opt/perforce/helix-web-services/bin/hws_configure
|sudo service nginx start
|sudo initctl reload-configuration
|sudo initctl start helix_web_services
""".stripMargin()
}
node('master') {
unarchive mapping: ['**/helix-web-services.tgz': '.']
sh """#!/bin/bash --login
|rvm use "2.2.3@#{job_name}"
|gem install bundler
|set -e
|echo 'installing bundle dependencies'
|bundle install
|cd helix_web_services && bundle install && cd ..
|cd helix_web_services_client && bundle install && cd ..
|set -x
|rake clean
|rake 'remotetest[#{test_centos6}]'
|mv helix_web_services_client/spec-output/helix_web_services_client_specs.html helix_web_services_client/spec-output/helix_web_services_client_specs-centos6.html
""".stripMargin()
archive '**/spec-output/'
}
mail subject: "HWS Build ${env.BUILD_NUMBER} OK", to: '#{mailto}', body: "Jenkins job URL: ${env.BUILD_URL}"
} catch (e) {
def w = new StringWriter()
e.printStackTrace(new PrintWriter(w))
mail subject: "HWS Build ${env.BUILD_NUMBER} Failed: ${e.message}", to: '#{mailto}', body: "Jenkins job URL: ${env.BUILD_URL}\\n\\n${w}"
throw e
}
END
xml =<<-END.gsub(/^[ ]{8}/, '')
<flow-definition plugin="workflow-job@1.10">
<actions/>
<description/>
<keepDependencies>false</keepDependencies>
<properties>
</properties>
<logRotator class="hudson.tasks.LogRotator">
<daysToKeep>60</daysToKeep>
<numToKeep>10</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>-1</artifactNumToKeep>
</logRotator>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition" plugin="workflow-cps@1.10">
<script>#{REXML::Text.new(workflow_script, true, nil, false)}</script>
<sandbox>false</sandbox>
</definition>
<triggers>
<hudson.triggers.TimerTrigger>
<spec>H 1 * * *</spec>
</hudson.triggers.TimerTrigger>
</triggers>
</flow-definition>
END
client.job.create_or_update(job_name, xml)
end
private
def client
JenkinsApi::Client.new(server_url: url,
log_level: Logger::WARN)
end
end
end
# |
Change |
User |
Description |
Committed |
|
#1
|
15741 |
ptomiak |
Branch HWS for my use. |
|
|