Skip to content

Commit

Permalink
[kie-issues#777] Allow restricting jenkins agent labels... (#1165)
Browse files Browse the repository at this point in the history
This change should allow restricting on which nodes pipeline can run. If environment variable 'FAULTY_NODES' is set or inherited from parent folders, nodes listed here will be added to the label expression to avoid them. This way we can have a single source (KIE folder in jenkins) when we can exclude faulty nodes before Apache admins remove the node, which is sometimes lengthy procedure.
  • Loading branch information
cimbalek authored Jan 31, 2024
1 parent ecac201 commit 3ca94f0
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 20 deletions.
8 changes: 5 additions & 3 deletions .ci/jenkins/Jenkinsfile.build-kogito-ci-image
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import org.jenkinsci.plugins.workflow.libs.Library

pipeline {
agent {
label 'ubuntu'
}
libraries {
lib("jenkins-pipeline-shared-libraries@${BRANCH_NAME}")
}

agent {
label util.getLabel('ubuntu')
}

environment {
DOCKER_CONFIG = "${WORKSPACE}/.docker"

Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.build-operator-node
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jenkinsci.plugins.workflow.libs.Library

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.nightly
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ UNSTABLE_STAGES = [:]
// Should be multibranch pipeline
pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.nightly.cloud
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ promoteImageParamsPrefix = 'PROMOTE_IMAGE'
// Should be multibranch pipeline
pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.release
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ releaseProperties = [:]

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

// parameters {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.release.cloud
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ promoteImageParamsPrefix = 'PROMOTE_IMAGE'

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

// parameters {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.setup-branch
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ UNSTABLE_STAGES = [:]

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.setup-branch.cloud
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ examplesImagesParamsPrefix = 'EXAMPLES_IMAGES'

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
2 changes: 1 addition & 1 deletion .ci/jenkins/Jenkinsfile.tools.update-jenkins-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ branchCreated = false

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class TestJenkinsfileNightly extends SingleFileDeclarativePipelineTest {
addEnvVar('STAGE_NAME', 'STAGE_NAME')
addEnvVar('BUILD_NUMBER', 'BUILD_NUMBER')
addEnvVar('BUILD_URL', 'BUILD_URL')
addEnvVar('FAULTY_NODES', 'faultyNode99')

helper.addShMock('date -u "+%Y-%m-%d"', 'date', 0)

Expand All @@ -58,6 +59,7 @@ class TestJenkinsfileNightly extends SingleFileDeclarativePipelineTest {
mockSharedLibVarsCall('githubscm', 'resolveRepository', { repo, author, branch, ignoreErrors, credsId -> registerTestCallstack('githubscm.resolveRepository', "${repo}, ${author}, ${branch}, ${ignoreErrors}, ${credsId}") })
mockSharedLibVarsCall('githubscm', 'createBranch', { branch -> registerTestCallstack('githubscm.createBranch', "${branch}") })
mockSharedLibVarsCall('githubscm', 'pushObject', { remote, branch, credsId -> registerTestCallstack('githubscm.pushObject', "${remote}, ${branch}, ${credsId}") })
mockSharedLibVarsCall('util', 'getLabel', { label -> return label})

}
@Test
Expand Down
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ This repository contains some of the pipelines of Kogito project.
- [GitHub Action checks](#github-action-checks)
- [Sonar cloud](#sonar-cloud)
- [Configuration of pipelines](#configuration-of-pipelines)
- [Source Code](#source-code)
- [Pipelines](#pipelines)
- [Shared Pipeline libraries](#shared-pipeline-libraries)
- [Jenkins](#jenkins)
- [Jenkins KIE folder](#jenkins-kie-folder)
- [Jenkins jobs generation](#jenkins-jobs-generation)
- [Zulip notifications](#zulip-notifications)
- [Format](#format)
Expand Down Expand Up @@ -132,9 +136,35 @@ NOTE: test coverage analysis is executed only by **Jenkins PR simple build&test*

# Configuration of pipelines

## Source Code
*Note: Creating separate readme.md documenting how-tos and best practices for implementing pipelines might be useful*

### Pipelines
In this repository two types of pipelines can be found:
- **Kogito pipelines** (obviously) - located in the [.ci/jenkins](./.ci/jenkins) folder
- **Seed jobs library** - see [Jenkins documentation](../docs/jenkins.md)

### Shared pipeline libraries
Apart from these pipelines, the `jenkins-pipeline-shared-libraries` are also stored in this repository. Functions and classes contained in these libraries can be freely used in all pipelines located under [KIE Jenkins folder](https://ci-builds.apache.org/job/KIE). Just include correct import and annotation in your Jenkinsfile:
```
import org.jenkinsci.plugins.workflow.libs.Library
@Library('jenkins-pipeline-shared-libraries')_
```
For more details please see our [Jenkins pipelines shared libraries documentation](./jenkins-pipeline-shared-libraries/README.md) and [Jenkins.io documentation](https://www.jenkins.io/doc/book/pipeline/shared-libraries/)

## Jenkins

All pipelines can be found in [kogito Jenkins folder](https://eng-jenkins-csb-business-automation.apps.ocp-c1.prod.psi.redhat.com/job/KIE/job/kogito).
### Jenkins KIE folder

All KIE jobs (pipelines) can be found in [KIE Jenkins folder](https://ci-builds.apache.org/job/KIE)<br />
For this folder and all its descendants there is several useful things set at this folder level:<br />
- **Pipeline library** - accessible in pipelines under name `jenkins-pipeline-shared-libraries` it gives access to some useful functions used throughout various KIE pipelines. More details can be found in our [Jenkins pipeline shared libraries documentation](./jenkins-pipeline-shared-libraries/README.md) and in the [previous chapter](#source-code)
- **Environment Variables** - Environment variables set here are inherited by all the folders and jobs located in the [KIE folder](https://ci-builds.apache.org/job/KIE) tree in Jenkins. However, they can be overridden or extended. You can modify the variables by clicking `Configure` in the left menu (if you have necessary permissions). Currently present Environment Variables are:
- **FAULTY_NODES** - Comma separated list of Jenkins execution nodes that are faulty in some way and cause KIE jobs to fail. This variable is expected by the *pipeline-library* function `getLabel(String label)`, which extends desired `label` by expression that ensures avoiding these faulty nodes. This way we can increase durability of KIE automation by the time the Apache CI team fixes the issue with faulty node.


All pipelines from this repository can be found in [kogito Jenkins folder](https://ci-builds.apache.org/job/KIE/job/kogito/).

### Jenkins jobs generation

Expand Down
1 change: 1 addition & 0 deletions dsl/seed/jenkinsfiles/Jenkinsfile.buildchain
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pipeline {
agent {
docker {
image env.AGENT_DOCKER_BUILDER_IMAGE
label util.getLabel(agentLabel)
args env.AGENT_DOCKER_BUILDER_ARGS
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jenkinsci.plugins.workflow.libs.Library

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

environment {
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.release.prepare
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositoriesToBranch = []

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

environment {
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.remove.branches
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.kie.jenkins.MavenCommand
pipeline {

agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options{
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.seed.branch
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SeedJobUtils.createSeedJobTrigger(

pipeline {
agent {
label "${env.AGENT_LABEL}"
label util.getLabel(env.AGENT_LABEL)
}

tools {
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.seed.main
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ seedConfig = [:]

pipeline {
agent {
label "${env.AGENT_LABEL}"
label util.getLabel(env.AGENT_LABEL)
}

options {
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.seed.trigger
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.jenkinsci.plugins.workflow.libs.Library

pipeline {
agent {
label "${env.AGENT_LABEL}"
label util.getLabel(env.AGENT_LABEL)
}

options {
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.tools.toggle-triggers
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.kie.jenkins.MavenCommand

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

options {
Expand Down
2 changes: 1 addition & 1 deletion dsl/seed/jenkinsfiles/Jenkinsfile.update-quarkus-version
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ failingRepos = []

pipeline {
agent {
label 'ubuntu'
label util.getLabel('ubuntu')
}

environment {
Expand Down
16 changes: 16 additions & 0 deletions jenkins-pipeline-shared-libraries/vars/util.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,19 @@ void waitForDocker() {
sleep(10) // give it some ahead time not to invoke docker exec immediately after container start
sh 'wait-for-docker.sh' // script in kogito-ci-build image itself put in /usr/local/bin
}

/**
* Method to wrap original label and exclude nodes that are marked as faulty in some of the parent folders.
* This environment variable is inherited down the folder tree and available in jobs.
* @param label Node label to be used
* @return Node label extended with an expression ensuring to exclude nodes marked as faulty.
*/
String getLabel(String label) {
String faultyNodesString = env.FAULTY_NODES
if((faultyNodesString == null) || faultyNodesString.isEmpty()) {
return label
}
String[] faultyNodes = faultyNodesString.split(',')
String result = "(${label}) && !(${String.join(' || ', faultyNodes)})"
return result.toString()
}

0 comments on commit 3ca94f0

Please sign in to comment.