Merge "Fixed gating pipeline issue"
diff --git a/test-devops-portal-pipeline.groovy b/test-devops-portal-pipeline.groovy
new file mode 100644
index 0000000..a720745
--- /dev/null
+++ b/test-devops-portal-pipeline.groovy
@@ -0,0 +1,127 @@
+/**
+* OSS - The DevOps Portal Testing Pipeline
+* CREDENTIALS_ID - gerrit credentials id
+**/
+
+gerrit = new com.mirantis.mk.Gerrit()
+common = new com.mirantis.mk.Common()
+
+def getProjectName(gerritRef, defaultGitRef) {
+ def refSpec
+ if (gerritRef) {
+ refSpec = gerritRef
+ } else {
+ refSpec = defaultGitRef
+ }
+ def refValue = refSpec.tokenize('/').takeRight(2).join('')
+ return "oss${BUILD_NUMBER}${refValue}"
+}
+
+def executeCmd(user, project, cmd) {
+ common.infoMsg("Starting command: ${cmd}")
+ wrap([$class: 'AnsiColorBuildWrapper']) {
+ // Docker sets HOME=/ ignoring that it have to be HOME=/opt/workspace,
+ // as `docker-compose exec` does not support to pass environment
+ // variables, then `docker exec` is used.
+ sh("docker exec --user=${user} --env=HOME=/opt/workspace ${project}_devopsportal_1 ${cmd}")
+ }
+ common.successMsg("Successfully completed: ${cmd}")
+}
+
+def gerritRef
+try {
+ gerritRef = GERRIT_REFSPEC
+} catch (MissingPropertyException e) {
+ gerritRef = null
+}
+
+def defaultGitRef, defaultGitUrl
+try {
+ defaultGitRef = DEFAULT_GIT_REF
+ defaultGitUrl = DEFAULT_GIT_URL
+} catch (MissingPropertyException e) {
+ defaultGitRef = null
+ defaultGitUrl = null
+}
+def checkouted = false
+
+node("vm") {
+ def composePath = 'docker/stack/docker-compose.yml'
+ def projectName
+ def jenkinsUser
+
+ try {
+ stage('Checkout Source Code') {
+ if (gerritRef) {
+ // job is triggered by Gerrit
+ checkouted = gerrit.gerritPatchsetCheckout ([
+ credentialsId : CREDENTIALS_ID,
+ withWipeOut : true,
+ ])
+ } else if(defaultGitRef && defaultGitUrl) {
+ checkouted = gerrit.gerritPatchsetCheckout(defaultGitUrl, defaultGitRef, "HEAD", CREDENTIALS_ID)
+ }
+ if(!checkouted){
+ throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
+ }
+ }
+
+ projectName = getProjectName(gerritRef, defaultGitRef)
+
+ stage('Setup Up Stack') {
+ sh("docker-compose --file ${composePath} --project-name=${projectName} pull")
+ sh("docker-compose --file ${composePath} --project-name=${projectName} up -d --force-recreate")
+ common.successMsg("Stack with the ${projectName} is started.")
+ }
+
+ def jenkinsUID = common.getJenkinsUid()
+ def jenkinsGID = common.getJenkinsGid()
+
+ jenkinsUser = "${jenkinsUID}:${jenkinsGID}"
+
+ stage('Print Environment Information') {
+ sh("docker-compose version")
+ sh("docker version")
+ executeCmd(jenkinsUser, projectName, "npm config get")
+ executeCmd(jenkinsUser, projectName, "env")
+ executeCmd(jenkinsUser, projectName, "ls -lan")
+ }
+
+ stage('Install Dependencies') {
+ executeCmd(jenkinsUser, projectName, "npm install")
+ }
+ stage('Run Linter Tests') {
+ executeCmd(jenkinsUser, projectName, "npm run lint")
+ }
+ stage('Run Unit Tests') {
+ timeout(4) {
+ executeCmd(jenkinsUser, projectName, "npm run test:unit")
+ }
+ }
+ stage('Run Function Tests') {
+ timeout(8) {
+ try {
+ executeCmd(jenkinsUser, projectName, "npm run test:functional")
+ } catch (err) {
+ archiveArtifacts(
+ artifacts: "test_output/**/*.png",
+ allowEmptyArchive: true,
+ )
+ throw err
+ }
+ }
+ }
+ } catch (err) {
+ currentBuild.result = 'FAILURE'
+ common.errorMsg("Build failed due to error: ${err}")
+ throw err
+ } finally {
+ common.sendNotification(currentBuild.result, "" ,["slack"])
+ stage('Cleanup') {
+ wrap([$class: 'AnsiColorBuildWrapper']) {
+ sh("docker-compose -f ${composePath} -p ${projectName} down")
+ }
+ }
+ }
+}
+
diff --git a/test-nodejs-pipeline.groovy b/test-nodejs-pipeline.groovy
index 36abbd7..a720745 100644
--- a/test-nodejs-pipeline.groovy
+++ b/test-nodejs-pipeline.groovy
@@ -1,23 +1,31 @@
/**
-* JS testing pipeline
+* OSS - The DevOps Portal Testing Pipeline
* CREDENTIALS_ID - gerrit credentials id
-* COMPOSE_PATH - path to compose file in repository
-* NODE_IMAGE - NodeJS with NPM Docker image name
-* COMMANDS - a list of command(s) to run
**/
gerrit = new com.mirantis.mk.Gerrit()
common = new com.mirantis.mk.Common()
-def executeCmd(user, containerName, cmd) {
- stage(cmd) {
- assert containerName != null
- common.infoMsg("Starting command: ${cmd}")
- wrap([$class: 'AnsiColorBuildWrapper']) {
- sh("docker exec --user=${user} ${containerName} ${cmd}")
- }
- common.successMsg("Successfully completed: ${cmd}")
+def getProjectName(gerritRef, defaultGitRef) {
+ def refSpec
+ if (gerritRef) {
+ refSpec = gerritRef
+ } else {
+ refSpec = defaultGitRef
}
+ def refValue = refSpec.tokenize('/').takeRight(2).join('')
+ return "oss${BUILD_NUMBER}${refValue}"
+}
+
+def executeCmd(user, project, cmd) {
+ common.infoMsg("Starting command: ${cmd}")
+ wrap([$class: 'AnsiColorBuildWrapper']) {
+ // Docker sets HOME=/ ignoring that it have to be HOME=/opt/workspace,
+ // as `docker-compose exec` does not support to pass environment
+ // variables, then `docker exec` is used.
+ sh("docker exec --user=${user} --env=HOME=/opt/workspace ${project}_devopsportal_1 ${cmd}")
+ }
+ common.successMsg("Successfully completed: ${cmd}")
}
def gerritRef
@@ -38,10 +46,12 @@
def checkouted = false
node("vm") {
- def containerName
- def uniqId
+ def composePath = 'docker/stack/docker-compose.yml'
+ def projectName
+ def jenkinsUser
+
try {
- stage('Checkout source code') {
+ stage('Checkout Source Code') {
if (gerritRef) {
// job is triggered by Gerrit
checkouted = gerrit.gerritPatchsetCheckout ([
@@ -55,30 +65,51 @@
throw new Exception("Cannot checkout gerrit patchset, GERRIT_REFSPEC and DEFAULT_GIT_REF is null")
}
}
- stage('Start container') {
- def workspace = common.getWorkspace()
- def timeStamp = new Date().format("HHmmss", TimeZone.getTimeZone('UTC'))
- if (gerritRef) {
- uniqId = gerritRef.tokenize('/').takeRight(2).join('') + timeStamp
- } else {
- uniqId = defaultGitRef.tokenize('/').takeRight(2).join('') + timeStamp
- }
- sh("docker-compose -f ${COMPOSE_PATH} -p ${uniqId} up -d")
- containerName = "${uniqId}_devopsportal_1"
- common.successMsg("Container with id ${containerName} started.")
+
+ projectName = getProjectName(gerritRef, defaultGitRef)
+
+ stage('Setup Up Stack') {
+ sh("docker-compose --file ${composePath} --project-name=${projectName} pull")
+ sh("docker-compose --file ${composePath} --project-name=${projectName} up -d --force-recreate")
+ common.successMsg("Stack with the ${projectName} is started.")
}
def jenkinsUID = common.getJenkinsUid()
def jenkinsGID = common.getJenkinsGid()
- def jenkinsUser = "${jenkinsUID}:${jenkinsGID}"
- executeCmd(jenkinsUser, containerName, "npm install")
+ jenkinsUser = "${jenkinsUID}:${jenkinsGID}"
- def cmds = COMMANDS.tokenize('\n')
- for (int i = 0; i < cmds.size(); i++) {
- timeout(5) {
- executeCmd(jenkinsUser, containerName, cmds[i])
- }
+ stage('Print Environment Information') {
+ sh("docker-compose version")
+ sh("docker version")
+ executeCmd(jenkinsUser, projectName, "npm config get")
+ executeCmd(jenkinsUser, projectName, "env")
+ executeCmd(jenkinsUser, projectName, "ls -lan")
+ }
+
+ stage('Install Dependencies') {
+ executeCmd(jenkinsUser, projectName, "npm install")
+ }
+ stage('Run Linter Tests') {
+ executeCmd(jenkinsUser, projectName, "npm run lint")
+ }
+ stage('Run Unit Tests') {
+ timeout(4) {
+ executeCmd(jenkinsUser, projectName, "npm run test:unit")
+ }
+ }
+ stage('Run Function Tests') {
+ timeout(8) {
+ try {
+ executeCmd(jenkinsUser, projectName, "npm run test:functional")
+ } catch (err) {
+ archiveArtifacts(
+ artifacts: "test_output/**/*.png",
+ allowEmptyArchive: true,
+ )
+ throw err
+ }
+ }
}
} catch (err) {
currentBuild.result = 'FAILURE'
@@ -86,22 +117,11 @@
throw err
} finally {
common.sendNotification(currentBuild.result, "" ,["slack"])
- stage('Attach artifacts') {
- if (containerName != null) {
- archiveArtifacts(
- artifacts: "test_output/screenshots/*.png",
- )
- }
- }
stage('Cleanup') {
- if (containerName != null) {
- dockerCleanupCommands = ['stop', 'rm -f']
- for (int i = 0; i < dockerCleanupCommands.size(); i++) {
- sh("docker-compose -f ${COMPOSE_PATH} -p ${uniqId} ${dockerCleanupCommands[i]} || true")
- }
- sh("docker network rm ${uniqId}_default || true")
- common.infoMsg("Container with id ${containerName} was removed.")
+ wrap([$class: 'AnsiColorBuildWrapper']) {
+ sh("docker-compose -f ${composePath} -p ${projectName} down")
}
}
}
}
+
diff --git a/test-salt-model-node.groovy b/test-salt-model-node.groovy
index 53f5e75..117971b 100644
--- a/test-salt-model-node.groovy
+++ b/test-salt-model-node.groovy
@@ -8,6 +8,7 @@
* NODE_TARGET
* SYSTEM_GIT_URL
* SYSTEM_GIT_REF
+ * FORMULAS_SOURCE
*/
def common = new com.mirantis.mk.Common()
@@ -51,7 +52,7 @@
stage("test node") {
if (checkouted) {
def workspace = common.getWorkspace()
- saltModelTesting.setupAndTestNode(NODE_TARGET, EXTRA_FORMULAS, workspace)
+ saltModelTesting.setupAndTestNode(NODE_TARGET, EXTRA_FORMULAS, workspace, FORMULAS_SOURCE)
}
}
} catch (Throwable e) {
diff --git a/test-salt-models-pipeline.groovy b/test-salt-models-pipeline.groovy
index f2a38f9..7278e8d 100644
--- a/test-salt-models-pipeline.groovy
+++ b/test-salt-models-pipeline.groovy
@@ -21,6 +21,13 @@
gerritRef = null
}
+def formulasSource
+try {
+ formulasSource = FORMULAS_SOURCE
+} catch (MissingPropertyException e) {
+ formulasSource = "pkg"
+}
+
def defaultGitRef, defaultGitUrl
try {
defaultGitRef = DEFAULT_GIT_REF
@@ -79,26 +86,26 @@
def acc = 0
for (int i = 0; i < nodes.size(); i++) {
def testTarget = sh(script: "basename ${nodes[i]} .yml", returnStdout: true).trim()
-
- if (acc < PARALLEL_NODE_GROUP_SIZE.toInteger()) {
- branches[testTarget] = {
- build job: "test-salt-model-node", parameters: [
- [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
- [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
- [$class: 'StringParameterValue', name: 'NODE_TARGET', value: testTarget],
- [$class: 'StringParameterValue', name: 'EXTRA_FORMULAS', value: EXTRA_FORMULAS],
- [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
- [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: SYSTEM_GIT_URL],
- [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: SYSTEM_GIT_REF]
- ]}
- acc++;
- } else {
+ if (acc >= PARALLEL_NODE_GROUP_SIZE.toInteger()) {
parallel branches
- acc = 0
branches = [:]
+ acc = 0
}
+
+ branches[testTarget] = {
+ build job: "test-salt-model-node", parameters: [
+ [$class: 'StringParameterValue', name: 'DEFAULT_GIT_URL', value: defaultGitUrl],
+ [$class: 'StringParameterValue', name: 'DEFAULT_GIT_REF', value: defaultGitRef],
+ [$class: 'StringParameterValue', name: 'NODE_TARGET', value: testTarget],
+ [$class: 'StringParameterValue', name: 'FORMULAS_SOURCE', value: formulasSource],
+ [$class: 'StringParameterValue', name: 'EXTRA_FORMULAS', value: EXTRA_FORMULAS],
+ [$class: 'StringParameterValue', name: 'CREDENTIALS_ID', value: CREDENTIALS_ID],
+ [$class: 'StringParameterValue', name: 'SYSTEM_GIT_URL', value: SYSTEM_GIT_URL],
+ [$class: 'StringParameterValue', name: 'SYSTEM_GIT_REF', value: SYSTEM_GIT_REF]
+ ]}
+ acc++;
}
- if (acc > 0) {
+ if (acc != 0) {
parallel branches
}
}