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

[CI] retry if environmental issues #22662

Closed
wants to merge 16 commits into from
Closed
Changes from 4 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
28 changes: 25 additions & 3 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,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
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
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(fileExists('environmental-issue')) {
sleep 10
runCommand(args)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The file is not deleted explicitly, it is true that runCommand deletes the folder but it is weird/hiden. Also, there is no stop condition, what happens if a tool is no longer available for installation? I think that will enter on an infinite loop

Copy link
Member Author

Choose a reason for hiding this comment

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

  • Actually the file is created in the top level agent, therefore this approach might cause issues for some other stages. It seems this approach might not be needed with files but with global variables. Good catch!
  • No infinite loops at all, but two runs since it calls the runCommand rather than itself.

}
}

/**
* 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 +361,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 +372,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,14 +390,17 @@ def withBeatsEnv(Map args = [:], Closure body) {
upload = true
error("Error '${err.toString()}'")
} finally {
if (archive) {
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()
}
if (environmentalIssue) {
writeFile file: 'environmental-issue', text: 'environmental-issue'
}
}
}
}
Expand Down