Skip to content
Closed
Changes from 6 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
43 changes: 40 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import groovy.transform.Field
*/
@Field def stashedTestReports = [:]

/**
This is required to store any environmental issues to retry if so
*/
@Field def environmentalIssues = [:]

pipeline {
agent { label 'ubuntu-18 && immutable' }
environment {
Expand Down Expand Up @@ -260,12 +265,28 @@ def k8sTest(Map args = [:]) {
}
}

/**
* This method is a wrapper to run the runCommand method and retry if there are
* environmental issues. Therefore it passes the arguments to the runCommand.
* For further details regarding the arguments please refers to the runCommand method.
*/
def target(Map args = [:]) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do think about a more descriptive name? I acknowledge references should be updated.

Suggested change
def target(Map args = [:]) {
def safeRunCommand(Map args = [:]) {

Alternatives?

  • runCommandWithEnviromentalIssues (longer)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was not intended to change the name at first, though it might be worth to add more clarity.

What do you think runCommandWithRetry?

try {
runCommand(args)
} catch (err) {
if(environmentalIssues?.get(args.id, false)) {
sleep 10
runCommand(args)
}
}
}

/**
* This method runs the given command supporting two kind of scenarios:
* - make -C <folder> then the dir(location) is not required, aka by disaling isMage: false
* - mage then the dir(location) is required, aka by enabling isMage: true.
*/
def target(Map args = [:]) {
def runCommand(Map args = [:]) {
def context = args.context
def command = args.command
def directory = args.get('directory', '')
Expand Down Expand Up @@ -345,6 +366,7 @@ def withBeatsEnv(Map args = [:], Closure body) {
dockerLogin(secret: "${DOCKERELASTIC_SECRET}", registry: "${DOCKER_REGISTRY}")
}
dir("${env.BASE_DIR}") {
def environmentalIssue = true
installTools()
if(isUnix()) {
// TODO (2020-04-07): This is a work-around to fix the Beat generator tests.
Expand All @@ -355,6 +377,8 @@ def withBeatsEnv(Map args = [:], Closure body) {
git config --global user.name "beatsmachine"
fi''')
}
// Pre-requisites to configure the environment were ok.
environmentalIssue = false
// Skip to upload the generated files by default.
def upload = false
try {
Expand All @@ -371,19 +395,32 @@ def withBeatsEnv(Map args = [:], Closure body) {
upload = true
error("Error '${err.toString()}'")
} finally {
if (archive) {
// If there are environmental issues then let's avoid the archiving of none files.
if (archive && !environmentalIssue) {
archiveTestOutput(testResults: testResults, artifacts: artifacts, id: args.id, upload: upload)
}
// Tear down the setup for the permamnent workers.
// Tear down the setup for the permanent workers.
catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') {
fixPermissions("${WORKSPACE}")
deleteDir()
}
analyseEnvironmentalIssues(id: args.id, isEnvironmentalIssue: environmentalIssue)
Comment thread
v1v marked this conversation as resolved.
Outdated
}
}
}
}

/**
* This method analyse if the existing stage failed with some enviornmental issues.
Comment thread
v1v marked this conversation as resolved.
Outdated
* So far the analysis is just purelly based on a boolean that detects if the installation of
Comment thread
v1v marked this conversation as resolved.
Outdated
* the required tools for building and testing in the agent were successfully installed.
* We can use this method in the future to analyse the build logs for searching specific patterns
* such as, not able to access the docker registry, or failed when pulling some docker images.
*/
def analyseEnvironmentalIssues(args) {
environmentalIssues[args.id] = args.environmentalIssue
}

/**
* This method fixes the filesystem permissions after the build has happenend. The reason is to
* ensure any non-ephemeral workers don't have any leftovers that could cause some environmental
Expand Down