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

Review dependency patterns in Jenkins #18004

Merged
merged 5 commits into from
Apr 28, 2020
Merged
Changes from all 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
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