Skip to content
Merged
Show file tree
Hide file tree
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
54 changes: 54 additions & 0 deletions JenkinsfileTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!groovy

// Loading libraries one by one
node {
checkout(scm)
def utils = load('src/org/istio/testutils/Utilities.groovy')
def gitUtils = load('src/org/istio/testutils/GitUtilities.groovy')
def bazel = load('src/org/istio/testutils/Bazel.groovy')
def goBuildNode = load('vars/goBuildNode.groovy')
def defaultNode = load('vars/defaultNode.groovy')
def buildNode = load('vars/buildNode.groovy')
def testNode = load('vars/testNode.groovy')

gitUtils.initialize()
bazel.setVars()

if (utils.runStage('PRESUBMIT')) {
def success = true
def branches = [
'goBuildNode': {
goBuildNode(gitUtils, 'istio.io/istio-testing') {
echo(env.PATH)
echo(env.GOPATH)
bazel.version()
}
},
'defaultNode': {
defaultNode(gitUtils) {
sh('ls -all')
}
},
'buildNode': {
buildNode(gitUtils) {
sh('ls -all')
bazel.version()
}
},
'testNode': {
testNode(gitUtils) {
sh('ls -all')
}
}
]
utils.updatePullRequest('run')
try {
parallel(branches)
} catch (Exception e) {
success = false
throw e
} finally {
utils.updatePullRequest('verify', success)
}
}
}
13 changes: 8 additions & 5 deletions src/org/istio/testutils/Bazel.groovy
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.istio.testutils

import static org.istio.testutils.Utilities.getWithDefault


BAZEL_ARGS = ''
BAZEL_BUILD_ARGS = ''


def setVars() {
BAZEL_ARGS = getWithDefault(env.BAZEL_ARGS)
BAZEL_BUILD_ARGS = getWithDefault(env.BAZEL_BUILD_ARGS)
BAZEL_ARGS = env.BAZEL_ARGS
BAZEL_BUILD_ARGS = env.BAZEL_BUILD_ARGS
}

def fetch(args) {
Expand Down Expand Up @@ -37,8 +34,14 @@ def test(args) {
}
}

def version() {
sh('bazel version')
}

def updateBazelRc(updateBazelrc='.bazelrc.jenkins') {
if (fileExists(updateBazelrc)) {
sh("cat ${updateBazelrc} >> .bazelrc")
}
}

return this
15 changes: 7 additions & 8 deletions src/org/istio/testutils/GitUtilities.groovy
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.istio.testutils

import static org.istio.testutils.Utilities.failIfNullOrEmpty

GIT_SHA = ''
BUCKET = ''
NOTIFY_LIST = ''
Expand All @@ -15,10 +13,9 @@ def initialize() {
}

def setVars() {
BUCKET = failIfNullOrEmpty(env.BUCKET, 'BUCKET env must be set.')
DEFAULT_SLAVE_LABEL = failIfNullOrEmpty(
env.DEFAULT_SLAVE_LABEL, 'DEFAULT_SLAVE_LABEL env must be set.')
NOTIFY_LIST = failIfNullOrEmpty(env.NOTIFY_LIST, 'NOTIFY_LIST env must be set.')
BUCKET = env.BUCKET
DEFAULT_SLAVE_LABEL = env.DEFAULT_SLAVE_LABEL
NOTIFY_LIST = env.NOTIFY_LIST
}

// In a pipeline, multiple scm checkout might checkout different version of the code.
Expand All @@ -37,7 +34,7 @@ def stashSourceCode(postcheckout_call = null) {
postcheckout_call()
}
// Setting source code related global variable once so it can be reused.
GIT_SHA = failIfNullOrEmpty(getRevision(), 'Could not find revision')
GIT_SHA = getRevision()
echo('Stashing source code')
fastStash('src-code', '.')
}
Expand Down Expand Up @@ -101,4 +98,6 @@ Find <a href='${url}'>artifacts</a> here
def getRevision() {
// Code needs to be checked out for this.
return sh(returnStdout: true, script: 'git rev-parse --verify HEAD').trim()
}
}

return this
2 changes: 2 additions & 0 deletions src/org/istio/testutils/Utilities.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ static def filterBranches(branches, regex) {
}
return filteredBranches
}

return this
12 changes: 7 additions & 5 deletions vars/buildNode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
Creates a node with the right label and checkout the source code.
*/

import org.istio.testutils.Utilities

def call(gitUtils, Closure body) {
utils = new Utilities()
def nodeLabel = utils.getParam('SLAVE_LABEL', gitUtils.DEFAULT_SLAVE_LABEL)
def nodeLabel = params.get('SLAVE_LABEL')
if (nodeLabel == null) {
nodeLabel = gitUtils.DEFAULT_SLAVE_LABEL
}
def buildNodeLabel = "${nodeLabel}-build"
node(buildNodeLabel) {
gitUtils.checkoutSourceCode()
body()
}
}
}

return this
12 changes: 7 additions & 5 deletions vars/defaultNode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Creates a node with the right label and checkout the source code.
*/

import org.istio.testutils.Utilities

def call(gitUtils, Closure body) {
utils = new Utilities()
def nodeLabel = utils.getParam('SLAVE_LABEL', gitUtils.DEFAULT_SLAVE_LABEL)
def nodeLabel = params.get('SLAVE_LABEL')
if (nodeLabel == null) {
nodeLabel = gitUtils.DEFAULT_SLAVE_LABEL
}
node(nodeLabel) {
gitUtils.checkoutSourceCode()
body()
}
}
}

return this
11 changes: 6 additions & 5 deletions vars/goBuildNode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
Creates a node with the right label and checkout the source code.
*/

import org.istio.testutils.Utilities


def call(gitUtils, goImportPath, Closure body) {
utils = new Utilities()
def nodeLabel = utils.getParam('SLAVE_LABEL', gitUtils.DEFAULT_SLAVE_LABEL)
def nodeLabel = params.get('SLAVE_LABEL')
if (nodeLabel == null) {
nodeLabel = gitUtils.DEFAULT_SLAVE_LABEL
}
def buildNodeLabel = "${nodeLabel}-build"
node(buildNodeLabel) {
def goPath = env.WORKSPACE
Expand All @@ -22,3 +21,5 @@ def call(gitUtils, goImportPath, Closure body) {
}
}
}

return this
12 changes: 7 additions & 5 deletions vars/testNode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
Creates a node with the right label and checkout the source code.
*/

import org.istio.testutils.Utilities

def call(gitUtils, Closure body) {
utils = new Utilities()
def nodeLabel = utils.getParam('SLAVE_LABEL', gitUtils.DEFAULT_SLAVE_LABEL)
def nodeLabel = params.get('SLAVE_LABEL')
if (nodeLabel == null) {
nodeLabel = gitUtils.DEFAULT_SLAVE_LABEL
}
def testNodeLabel = "${nodeLabel}-test"
node(testNodeLabel) {
gitUtils.checkoutSourceCode()
body()
}
}
}

return this