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

[APM-CI] add support to reference repository to gitCheckout #27

Merged
merged 3 commits into from
Jan 9, 2019
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
37 changes: 27 additions & 10 deletions src/test/groovy/GitCheckoutStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import static org.junit.Assert.assertTrue

class GitCheckoutStepTests extends BasePipelineTest {
Map env = [:]

@Override
@Before
void setUp() throws Exception {
super.setUp()

env.WORKSPACE = "WS"
binding.setVariable('env', env)

helper.registerAllowedMethod("sh", [Map.class], { "OK" })
helper.registerAllowedMethod("sh", [String.class], { "OK" })
helper.registerAllowedMethod("checkout", [String.class], { "OK" })
Expand Down Expand Up @@ -42,7 +42,7 @@ class GitCheckoutStepTests extends BasePipelineTest {
})
assertJobStatusSuccess()
}

@Test
void testBaseDir() throws Exception {
def script = loadScript("vars/gitCheckout.groovy")
Expand All @@ -57,7 +57,7 @@ class GitCheckoutStepTests extends BasePipelineTest {
})
assertJobStatusSuccess()
}

@Test
void testBranch() throws Exception {
def script = loadScript("vars/gitCheckout.groovy")
Expand All @@ -73,7 +73,24 @@ class GitCheckoutStepTests extends BasePipelineTest {
})
assertJobStatusSuccess()
}


@Test
void testReferenceRepo() throws Exception {
def script = loadScript("vars/gitCheckout.groovy")
script.scm = "SCM"
script.call(basedir: 'sub-folder', branch: 'master',
repo: 'git@github.com:elastic/apm-pipeline-library.git',
credentialsId: 'credentials-id',
reference: "repo")
printCallStack()
assertTrue(helper.callStack.findAll { call ->
call.methodName == "log"
}.any { call ->
callArgsToString(call).contains("Checkout master")
})
assertJobStatusSuccess()
}

@Test
void testErrorBranchIncomplete() throws Exception {
def script = loadScript("vars/gitCheckout.groovy")
Expand All @@ -86,7 +103,7 @@ class GitCheckoutStepTests extends BasePipelineTest {
callArgsToString(call).contains("No valid SCM config passed.")
})
}

@Test
void testErrorBranchNoCredentials() throws Exception {
def script = loadScript("vars/gitCheckout.groovy")
Expand All @@ -100,7 +117,7 @@ class GitCheckoutStepTests extends BasePipelineTest {
callArgsToString(call).contains("No valid SCM config passed.")
})
}

@Test
void testErrorBranchNoRepo() throws Exception {
def script = loadScript("vars/gitCheckout.groovy")
Expand All @@ -114,7 +131,7 @@ class GitCheckoutStepTests extends BasePipelineTest {
callArgsToString(call).contains("No valid SCM config passed.")
})
}

@Test
void testManuallyTriggered() throws Exception {
binding.getVariable('currentBuild').getBuildCauses = {
Expand All @@ -138,4 +155,4 @@ class GitCheckoutStepTests extends BasePipelineTest {
callArgsToString(call).contains("No valid SCM config passed.")
})
}
}
}
4 changes: 3 additions & 1 deletion vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ gitCheckout(basedir: 'sub-folder')
```
gitCheckout(basedir: 'sub-folder', branch: 'master',
repo: 'git@github.com:elastic/apm-pipeline-library.git',
credentialsId: 'credentials-id')
credentialsId: 'credentials-id',
reference: '/var/lib/jenkins/reference-repo.git')
```

* *basedir*: directory where checkout the sources.
* *repo*: the repository to use.
* *credentialsId*: the credentials to access to the repository.
* *branch*: the branch to checkout from the repo.
* *reference*: Repository to be used as reference repository.

## gitCreateTag
Create a git TAG named ${BUILD_TAG} and push it to the git repo.
Expand Down
55 changes: 31 additions & 24 deletions vars/gitCheckout.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,44 @@

gitCheckout(basedir: 'sub-folder', branch: 'master',
repo: 'git@github.com:elastic/apm-pipeline-library.git',
credentialsId: 'credentials-id')
credentialsId: 'credentials-id',
reference: '/var/lib/jenkins/reference-repo.git')

*/
def call(Map params = [:]){
def basedir = params.containsKey('basedir') ? params.basedir : "src"
def repo = params?.repo
def credentialsId = params?.credentialsId
def branch = params?.branch
def reference = params?.reference

withEnvWrapper() {
dir("${basedir}"){
if(env?.BRANCH_NAME){
log(level: 'INFO', text: "gitCheckout: Checkout SCM ${env.BRANCH_NAME}")
checkout scm
} else if (branch && branch != ""
&& repo
&& credentialsId){
log(level: 'INFO', text: "gitCheckout: Checkout ${branch} from ${repo} with credentials ${credentialsId}")
checkout([$class: 'GitSCM', branches: [[name: "${branch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: "${credentialsId}",
url: "${repo}"]]])
} else {
error "No valid SCM config passed."
}
githubEnv()
if(!isManualyTrigger()){
githubPrCheckApproved()
}
def extensions = []

if(reference != null){
extensions.add([$class: 'CloneOption', depth: 1, noTags: false, reference: "${reference}", shallow: true])
log(level: 'DEBUG', text: "gitCheckout: Reference repo enabled ${extensions.toString()}")
}

dir("${basedir}"){
if(env?.BRANCH_NAME && branch == null){
log(level: 'INFO', text: "gitCheckout: Checkout SCM ${env.BRANCH_NAME}")
checkout scm
} else if (branch && branch != ""
&& repo
&& credentialsId){
log(level: 'INFO', text: "gitCheckout: Checkout ${branch} from ${repo} with credentials ${credentialsId}")
checkout([$class: 'GitSCM', branches: [[name: "${branch}"]],
doGenerateSubmoduleConfigurations: false,
extensions: extensions,
submoduleCfg: [],
userRemoteConfigs: [[credentialsId: "${credentialsId}",
url: "${repo}"]]])
} else {
error "No valid SCM config passed."
}
githubEnv()
if(!isManualyTrigger()){
githubPrCheckApproved()
}
}
}
Expand All @@ -52,4 +59,4 @@ def isManualyTrigger(){
ret = true
}
return ret
}
}
4 changes: 3 additions & 1 deletion vars/gitCheckout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ gitCheckout(basedir: 'sub-folder')
```
gitCheckout(basedir: 'sub-folder', branch: 'master',
repo: 'git@github.com:elastic/apm-pipeline-library.git',
credentialsId: 'credentials-id')
credentialsId: 'credentials-id',
reference: '/var/lib/jenkins/reference-repo.git')
```

* *basedir*: directory where checkout the sources.
* *repo*: the repository to use.
* *credentialsId*: the credentials to access to the repository.
* *branch*: the branch to checkout from the repo.
* *reference*: Repository to be used as reference repository.

44 changes: 21 additions & 23 deletions vars/runIntegrationTestAxis.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,32 @@ def call(Map params = [:]){
if(agentType == null){
error "runIntegrationTestAxis: no valid agentType"
}

if(source == null){
error "runIntegrationTestAxis: no valid source to unstash"
}

withEnvWrapper() {
deleteDir()
unstash "${source}"
dir("${baseDir}"){
def parallelStages = [:]
def nodeVersions = readYaml(file: ymlFiles[agentType])
def elasticStackVersions = readYaml(file: ymlFiles["server"])
def serverKey = agentYamlVar["server"]
def agentKey = agentYamlVar[agentType]

def elasticStackVersNoExcluded = elasticStackVersions[serverKey]?.findAll{!elasticStackVersions?.exclude?.contains(it)}
def nodeVersNoExcluded = nodeVersions[agentKey]?.findAll{!nodeVersions?.exclude?.contains(it)}

elasticStackVersNoExcluded.each{ server ->
nodeVersNoExcluded.each{ agent ->
def tag = "${agentType} ${agent}-ES:${elasticStack}-APM:${server}"
def serverVer = server.tokenize(";")[0]
def opts = server.tokenize(";")[1] ? server.tokenize(";")[1] : ''
parallelStages[tag] = nodeIntegrationTest(source, tag, agent, serverVer, opts, agentType)
}

deleteDir()
unstash "${source}"
dir("${baseDir}"){
def parallelStages = [:]
def nodeVersions = readYaml(file: ymlFiles[agentType])
def elasticStackVersions = readYaml(file: ymlFiles["server"])
def serverKey = agentYamlVar["server"]
def agentKey = agentYamlVar[agentType]

def elasticStackVersNoExcluded = elasticStackVersions[serverKey]?.findAll{!elasticStackVersions?.exclude?.contains(it)}
def nodeVersNoExcluded = nodeVersions[agentKey]?.findAll{!nodeVersions?.exclude?.contains(it)}

elasticStackVersNoExcluded.each{ server ->
nodeVersNoExcluded.each{ agent ->
def tag = "${agentType} ${agent}-ES:${elasticStack}-APM:${server}"
def serverVer = server.tokenize(";")[0]
def opts = server.tokenize(";")[1] ? server.tokenize(";")[1] : ''
parallelStages[tag] = nodeIntegrationTest(source, tag, agent, serverVer, opts, agentType)
}
parallel(parallelStages)
}
parallel(parallelStages)
}
}

Expand Down
50 changes: 24 additions & 26 deletions vars/stepIntegrationTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,37 @@ def call(Map params = [:]){
def agentType = params?.agentType
def source = params?.source
def baseDir = params.containsKey('baseDir') ? params.baseDir : 'src/github.com/elastic/apm-integration-testing'

if(agentType == null){
error "stepIntegrationTest: no valid agentType"
}

if(source == null){
error "stepIntegrationTest: no valid source to unstash"
}

log(level: 'INFO', text: "${tag}")
withEnvWrapper() {
deleteDir()
unstash "${source}"
dir("${baseDir}"){
def pytestIni = "[pytest]\n"
pytestIni += "junit_suite_name = ${tag}\n"
pytestIni += "addopts = --color=yes -ra\n"
writeFile(file: "pytest.ini", text: pytestIni, encoding: "UTF-8")

try {
sh """#!/bin/bash
echo "${tag}"
export TMPDIR="${WORKSPACE}"
chmod ugo+rx ./scripts/ci/*.sh
./scripts/ci/${agentType}.sh
"""
} finally {
junit(
allowEmptyResults: true,
keepLongStdio: true,
testResults: "tests/results/*-junit*.xml")
deleteDir()
}
deleteDir()
unstash "${source}"
dir("${baseDir}"){
def pytestIni = "[pytest]\n"
pytestIni += "junit_suite_name = ${tag}\n"
pytestIni += "addopts = --color=yes -ra\n"
writeFile(file: "pytest.ini", text: pytestIni, encoding: "UTF-8")

try {
sh """#!/bin/bash
echo "${tag}"
export TMPDIR="${WORKSPACE}"
chmod ugo+rx ./scripts/ci/*.sh
./scripts/ci/${agentType}.sh
"""
} finally {
junit(
allowEmptyResults: true,
keepLongStdio: true,
testResults: "tests/results/*-junit*.xml")
deleteDir()
}
}
}