Repository: incubator-beam-site Updated Branches: refs/heads/asf-site 3ec3a49ef -> 8ba89346d
Add Jenkins job definitions for existing projects using Jenkins DSL Project: http://git-wip-us.apache.org/repos/asf/incubator-beam-site/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam-site/commit/3596eefa Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam-site/tree/3596eefa Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam-site/diff/3596eefa Branch: refs/heads/asf-site Commit: 3596eefaf149ce85f38cfa364c4c3363b1691ff1 Parents: 3ec3a49 Author: Davor Bonaci <da...@google.com> Authored: Sun Nov 13 01:49:37 2016 -0800 Committer: Davor Bonaci <da...@google.com> Committed: Mon Nov 14 17:56:10 2016 -0800 ---------------------------------------------------------------------- tools/common_job_properties.groovy | 106 ++++++++++++++++++++++++++++++++ tools/job_precommit_stage.groovy | 62 +++++++++++++++++++ tools/job_precommit_test.groovy | 47 ++++++++++++++ tools/job_seed.groovy | 32 ++++++++++ 4 files changed, 247 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-beam-site/blob/3596eefa/tools/common_job_properties.groovy ---------------------------------------------------------------------- diff --git a/tools/common_job_properties.groovy b/tools/common_job_properties.groovy new file mode 100644 index 0000000..6e30023 --- /dev/null +++ b/tools/common_job_properties.groovy @@ -0,0 +1,106 @@ +// Contains functions that help build Jenkins projects. Functions typically set +// common properties that are shared among all Jenkins projects. +class common_job_properties { + + // Sets common top-level job properties. + static def setTopLevelJobProperties(def context) { + + // GitHub project. + context.properties { + githubProjectUrl('https://github.com/apache/incubator-beam-site/') + } + + // Restrict this project to run only on Jenkins executors dedicated to the + // Apache Beam project. + context.label('beam') + + // Discard old builds. Build records are only kept up to this number of days. + context.logRotator { + daysToKeep(14) + } + + // Source code management. + context.scm { + git { + remote { + url('https://github.com/apache/incubator-beam-site.git') + refspec('+refs/heads/*:refs/remotes/origin/* ' + + '+refs/pull/*:refs/remotes/origin/pr/*') + } + branch('${sha1}') + extensions { + cleanAfterCheckout() + } + } + } + + context.parameters { + // This is a recommended setup if you want to run the job manually. The + // ${sha1} parameter needs to be provided, and defaults to the main branch. + stringParam( + 'sha1', + 'asf-site', + 'Commit id or refname (eg: origin/pr/9/head) you want to build.') + } + + context.wrappers { + // Abort the build if it's stuck for more minutes than specified. + timeout { + absolute(30) + abortBuild() + } + } + } + + // Sets the pull request build trigger. + static def setPullRequestBuildTrigger(def context, + def commitStatusContext, + def successComment = '--none--') { + context.triggers { + githubPullRequest { + admins(['asfbot']) + useGitHubHooks() + orgWhitelist(['apache']) + allowMembersOfWhitelistedOrgsAsAdmin() + permitAll() + + extensions { + commitStatus { + // This is the name that will show up in the GitHub pull request UI + // for this Jenkins project. + delegate.context(commitStatusContext) + } + + /* + This section is disabled, because of jenkinsci/ghprb-plugin#417 issue. + For the time being, an equivalent configure section below is added. + + // Comment messages after build completes. + buildStatus { + completedStatus('SUCCESS', successComment) + completedStatus('FAILURE', '--none--') + completedStatus('ERROR', '--none--') + } + */ + } + } + } + + // Comment messages after build completes. + context.configure { + def messages = it / triggers / 'org.jenkinsci.plugins.ghprb.GhprbTrigger' / extensions / 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildStatus' / messages + messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' { + message(successComment) + result('SUCCESS') + } + messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' { + message('--none--') + result('ERROR') + } + messages << 'org.jenkinsci.plugins.ghprb.extensions.comments.GhprbBuildResultMessage' { + message('--none--') + result('FAILURE') + } + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-beam-site/blob/3596eefa/tools/job_precommit_stage.groovy ---------------------------------------------------------------------- diff --git a/tools/job_precommit_stage.groovy b/tools/job_precommit_stage.groovy new file mode 100644 index 0000000..ad05c23 --- /dev/null +++ b/tools/job_precommit_stage.groovy @@ -0,0 +1,62 @@ +import common_job_properties + +// Defines a job. +job('beam_PreCommit_Website_Stage') { + description('Stages the pull requests proposed for the Apache Beam ' + + 'website to a temporary location to ease reviews.') + + // Set common parameters. + common_job_properties.setTopLevelJobProperties(delegate) + + // Set pull request build trigger. + common_job_properties.setPullRequestBuildTrigger( + delegate, + 'Jenkins: automatic staging of pull requests', + '\nJenkins built the site at commit id ${ghprbActualCommit} with ' + + 'Jekyll and staged it [here](http://apache-beam-website-pull-' + + 'requests.storage.googleapis.com/${ghprbPullId}/index.html). ' + + 'Happy reviewing.\n\nNote that any previous site has been deleted. ' + + 'This staged site will be automatically deleted after its TTL ' + + 'expires. Push any commit to the pull request branch or re-trigger ' + + 'the build to get it staged again.') + + steps { + // Run the following shell script as a build step. + shell ''' + # Install RVM. + gpg --keyserver hkp://keys.gnupg.net --recv-keys \\ + 409B6B1796C275462A1703113804BB82D39DC0E3 + \\curl -sSL https://get.rvm.io | bash + source /home/jenkins/.rvm/scripts/rvm + + # Install Ruby. + RUBY_VERSION_NUM=2.3.0 + rvm install ruby $RUBY_VERSION_NUM --autolibs=read-only + + # Install Bundler gem + PATH=~/.gem/ruby/$RUBY_VERSION_NUM/bin:$PATH + GEM_PATH=~/.gem/ruby/$RUBY_VERSION_NUM/:$GEM_PATH + gem install bundler --user-install + + # Install all needed gems. + bundle install --path ~/.gem/ + + # Remove current site if it exists. + GCS_PATH="gs://apache-beam-website-pull-requests/${ghprbPullId}/" + gsutil -m rm -r -f ${GCS_PATH} || true + + # Build the new site with the baseurl specified. + rm -fr ./content/ + bundle exec jekyll build --baseurl=/${ghprbPullId} + + # Install BeautifulSoup HTML Parser for python. + pip install --user beautifulsoup4 + + # Fix links on staged website. + python tools/append_index_html_to_internal_links.py + + # Upload the new site. + gsutil -m cp -R ./content/* ${GCS_PATH} + '''.stripIndent().trim() + } +} http://git-wip-us.apache.org/repos/asf/incubator-beam-site/blob/3596eefa/tools/job_precommit_test.groovy ---------------------------------------------------------------------- diff --git a/tools/job_precommit_test.groovy b/tools/job_precommit_test.groovy new file mode 100644 index 0000000..c6128a8 --- /dev/null +++ b/tools/job_precommit_test.groovy @@ -0,0 +1,47 @@ +import common_job_properties + +// Defines a job. +job('beam_PreCommit_Website_Test') { + description('Runs tests on the pull requests proposed for the Apache Beam ' + + 'website.') + + // Set common parameters. + common_job_properties.setTopLevelJobProperties(delegate) + + // Execute concurrent builds. Multiple builds of this project may be executed + // in parallel. This is safe because this build does not require exclusive + // access to any shared resources. + concurrentBuild() + + // Set pull request build trigger. + common_job_properties.setPullRequestBuildTrigger( + delegate, + 'Jenkins: test website (dead links, etc.)') + + steps { + // Run the following shell script as a build step. + shell ''' + # Install RVM. + gpg --keyserver hkp://keys.gnupg.net --recv-keys \\ + 409B6B1796C275462A1703113804BB82D39DC0E3 + \\curl -sSL https://get.rvm.io | bash + source /home/jenkins/.rvm/scripts/rvm + + # Install Ruby. + RUBY_VERSION_NUM=2.3.0 + rvm install ruby $RUBY_VERSION_NUM --autolibs=read-only + + # Install Bundler gem + PATH=~/.gem/ruby/$RUBY_VERSION_NUM/bin:$PATH + GEM_PATH=~/.gem/ruby/$RUBY_VERSION_NUM/:$GEM_PATH + gem install bundler --user-install + + # Install all needed gems. + bundle install --path ~/.gem/ + + # Build the new site and test it. + rm -fr ./content/ + bundle exec rake test + '''.stripIndent().trim() + } +} http://git-wip-us.apache.org/repos/asf/incubator-beam-site/blob/3596eefa/tools/job_seed.groovy ---------------------------------------------------------------------- diff --git a/tools/job_seed.groovy b/tools/job_seed.groovy new file mode 100644 index 0000000..a240b6c --- /dev/null +++ b/tools/job_seed.groovy @@ -0,0 +1,32 @@ +import common_job_properties + +// Defines the seed job, which creates or updates all other Jenkins projects. +job('beam_SeedJob_Website') { + description('Automatically configures all Apache Beam website Jenkins ' + + 'projects based on Jenkins DSL groovy files checked into the ' + + 'code repository.') + + // Set common parameters. + common_job_properties.setTopLevelJobProperties(delegate) + + // Run this job every night to revert back any accidental changes to the + // configuration. + triggers { + cron('0 6 * * *') + } + + steps { + dsl { + // A list or a glob of other groovy files to process. + external('tools/job_*.groovy') + + // If a job is removed from the script, disable it (rather than deleting). + removeAction('DISABLE') + } + } + + publishers { + // Notify the mailing list for each failed build. + mailer('d...@beam.incubator.apache.org', false, false) + } +}