Skip to content

Commit

Permalink
Review dependency patterns collection in Jenkins (#18004)
Browse files Browse the repository at this point in the history
Fix dependency checking for generators, looking now for dependencies
of the generators code itself (beatgen) and Metricbeat beater.
Stop looking for dependencies of libbeat in all beats, this is redundant
as they are already transitive dependencies.
Run collection of dependecies in the host instead of using docker, what
is slightly faster.
  • Loading branch information
jsoriano authored Apr 28, 2020
1 parent eb2dc26 commit f24f744
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pipeline {
steps {
deleteDir()
gitCheckout(basedir: "${BASE_DIR}")
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
dir("${BASE_DIR}"){
loadConfigEnvVars()
}
whenTrue(params.debug){
dumpFilteredEnvironment()
}
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
}
}
stage('Lint'){
Expand Down Expand Up @@ -853,7 +853,6 @@ def isChangedOSSCode(patterns) {
"^\\.ci/.*",
]
allPatterns.addAll(patterns)
allPatterns.addAll(getVendorPatterns('libbeat'))
return isChanged(allPatterns)
}

Expand All @@ -868,14 +867,17 @@ def isChangedXPackCode(patterns) {
"^\\.ci/.*",
]
allPatterns.addAll(patterns)
allPatterns.addAll(getVendorPatterns('x-pack/libbeat'))
return isChanged(allPatterns)
}

def loadConfigEnvVars(){
def empty = []
env.GO_VERSION = readFile(".go-version").trim()

withEnv(["HOME=${env.WORKSPACE}"]) {
sh(label: "Install Go ${env.GO_VERSION}", script: ".ci/scripts/install-go.sh")
}

// Libbeat is the core framework of Beats. It has no additional dependencies
// on other projects in the Beats repository.
env.BUILD_LIBBEAT = isChangedOSSCode(empty)
Expand Down Expand Up @@ -934,17 +936,25 @@ def loadConfigEnvVars(){
// involved.
env.BUILD_KUBERNETES = isChanged(["^deploy/kubernetes/.*"])

env.BUILD_GENERATOR = isChangedOSSCode(getVendorPatterns('generator'))
def generatorPatterns = ['^generator/.*']
generatorPatterns.addAll(getVendorPatterns('generator/common/beatgen'))
generatorPatterns.addAll(getVendorPatterns('metricbeat/beater'))
env.BUILD_GENERATOR = isChangedOSSCode(generatorPatterns)
}

/**
This method grab the dependencies of a Go module and transform them on regexp
*/
def getVendorPatterns(beatName){
def os = goos()
def goRoot = "${env.WORKSPACE}/.gvm/versions/go${GO_VERSION}.${os}.amd64"
def output = ""
docker.image("golang:${GO_VERSION}").inside{

withEnv([
"HOME=${env.WORKSPACE}/${env.BASE_DIR}",
"PATH=${env.WORKSPACE}/bin:${goRoot}/bin:${env.PATH}",
]) {
output = sh(label: 'Get vendor dependency patterns', returnStdout: true, script: """
export HOME=${WORKSPACE}/${BASE_DIR}
go list -mod=vendor -f '{{ .ImportPath }}{{ "\\n" }}{{ join .Deps "\\n" }}' ./${beatName}\
|awk '{print \$1"/.*"}'\
|sed -e "s#github.com/elastic/beats/v7/##g"
Expand Down

0 comments on commit f24f744

Please sign in to comment.