Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Jenkinsfile for parallelized ATH runs via Pipeline #157

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* The MIT License
*
* Copyright (c) 2016, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

/*
* This Jenkinsfile is intended to run on https://jenkins.ci.cloudbees.com and may fail anywhere else.
* It makes assumptions about plugins being installed, labels mapping to nodes that can build what is needed, etc.
*
* The required label is "hi-speed" */

// TODO: Figure out how to run just changed/affected-by-changes tests when running from a PR.
// TODO: Get https://issues.jenkins-ci.org/browse/JENKINS-33274 fixed and configured so that we don't have to run
// serially for the first run on a branch.

timestamps {
// Only keep the 50 most recent builds.
properties([[$class: 'jenkins.model.BuildDiscarderProperty', strategy: [$class: 'LogRotator',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be updated to new symbols.

numToKeepStr: '50']]])

stage "Load libs"
loadLibs { functions, ath ->

stage "Fetch WAR and ATH source"
parallel 'jenkins-war': { functions.stashJenkinsWar(war, ath.athLabel(), true) },
'get-ath': { ath.stashAth(functions) },
failFast: true

stage "Run tests"
def branches = ath.getAthBranches(
functions, // Used for things like getting the Maven environment set up.
ath.athLabel(), // What label to use for execution.
false, // Whether to archive JUnit report files for processing in a later job.
3, // Number of times to retry failed tests
4 // Parallel branch count, in addition to the cucumber branch
)

parallel branches
}
}

/**
* Loads the libraries using known parameters for repo/branch/node if they're specified, and then makes the libraries
* available in the execution of the body.
*
* @param body Closure to execute.
*/
def loadLibs(def body) {
String functionsRepo = defaultValueIfNotSet("FUNCTIONS_REPO", "jenkinsci/jenkins-project-pipeline-lib")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that run-time variation of a shared library is not currently supported in JENKINS-31155; would require a library step, which would not work with static typing. At any rate I do not see where this variable even could be defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway the Replay function lets you play with library changes more easily than what I am guessing this hook was for.

String functionsBranch = defaultValueIfNotSet("FUNCTIONS_BRANCH", "master")
String label = defaultValueIfNotSet("FUNCTIONS_LABEL", "hi-speed")

if (!functionsRepo.endsWith(".git")) {
functionsRepo = functionsRepo + ".git"
}

def functions
def ath

node(label) {
git changelog: false, poll: false, url: "git://github.com/" + functionsRepo, branch: functionsBranch

functions = load 'lib/functions.groovy'
ath = load 'lib/ath.groovy'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any value in sharing ath.groovy? I doubt anybody would use it without ATH sources.

Copy link
Member Author

@abayer abayer Jul 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main reasoning is so we can eventually branch the ATH without also forking the build tooling, if that makes any sense. And so we can have multiple jobs that use the ATH but may not all be building against the same branch etc...

}

body(functions, ath)
}

/**
* Given a parameter name and an optional default value, try to get the value of that parameter. If the parameter
* exists, it's not null, and its value isn't the empty string, return that. Otherwise, return the default value.
*
* @param paramName A String name of a build parameter
* @param defaultValue An optional default value if the parameter does not exist, is unset or is the empty string.
* @return The value of the parameter if appropriate, the default value otherwise.
*/
def defaultValueIfNotSet(String paramName, def defaultValue = null) {
def result = defaultValue

try {
def prop = getProperty(paramName)
if (prop != null && prop != '') {
result = prop
}
} catch (Exception e) {
// This just means the parameter doesn't exist at all, so let's move on.
}

return result
}