-
Notifications
You must be signed in to change notification settings - Fork 723
Use Jenkins pipelines #937
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
Merged
Merged
Changes from all commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
f06da91
Added job configuration for Jenkins pipelines
delvedor d5c2dfb
Added job name
delvedor 9d1bc16
Merge branch 'master' into jenkins-pipelines
delvedor f9c236f
Added basic Jenkinsfile
delvedor bd32b66
Updated Jenkinsfile
delvedor 8f59d7b
Updated Jenkinsfile
delvedor 9baf56a
Updated Jenkinsfile
delvedor 166ec82
[wip] Move from docker agent to labels (#924)
v1v f77a2d5
Updated Jenkinsfile
delvedor d6eeecb
Added env variables and stash dependencies
delvedor cdaab03
Debug ls
delvedor d42531c
Debug ls
delvedor ef1e4b1
Updated dir handling
delvedor b3ef2e0
Added unit test step
delvedor 48527b4
Updated agent handling and moved environment settings
delvedor 1973432
Updated es docker scripts
delvedor 859d42e
Added oss integration step
delvedor 0ac3d24
Refactor oss integration test step
delvedor c82418f
Debug logs
delvedor aeb6b0f
Moved stash outside of script block
delvedor 86fb91d
Updated oss integration test script
delvedor 4256f67
Merge branch 'master' into jenkins-pipelines
delvedor 1114b04
Debug logs
delvedor dd22f27
Updated path
delvedor 595ca63
Try with npm script
delvedor 9874648
Use BASE_DIR
delvedor 2bc6416
More debug checks
delvedor 96a5395
Test
delvedor ba5e7ef
Fix
delvedor 5a422a7
Updated elasticsearch script and Jenkinsfile
delvedor a46bac5
Use the correct context
delvedor affd927
Fixes
delvedor 1898e34
Use elastic network
delvedor 2b5f47b
Use root user
delvedor cc4e3cf
Add git
delvedor 52032d1
Fix script
delvedor 1efdc84
Comment stage
delvedor 2a9e350
Reenable stage
delvedor 7df6cbe
Run the script as root
delvedor d20297b
Merge branch 'master' into jenkins-pipelines
delvedor 3755c7d
Added xpack stage
delvedor 745a624
Use a custom Dockerfile
delvedor 1597c3f
Use a folder
delvedor 8037e19
Use alpine version
delvedor 1e0296a
Fix host
delvedor 653beb6
Updated elasticsearch docker scripts
delvedor 8aa1251
Move nodejsversion to its own variable
delvedor 868a54f
Run unit test in parallel
delvedor 3f8f284
Use a custom agent for the parallel build
delvedor 77cf228
Use env variable
delvedor 46fecae
Fix string
delvedor 7b016a9
Paralellize integration test
delvedor 80ae2b0
Comment out integration test
delvedor 3c5fcec
Added docker retry and reenabled integration test
delvedor 43ebff7
Fix scope
delvedor c9905c6
Added retry also for es docker
delvedor 2387a7f
Reorganized environment variables
delvedor 0d7c7a4
Use a single function for building docker containers
delvedor 1a27aaf
Use a function to define parallel jobs
delvedor c39c5b4
Refactored buildUnitTest
delvedor e388c0c
Added test reporting
delvedor aadfa15
Use xunit reporter
delvedor 588a553
Use junit reporter
delvedor 5f8eeb8
Merge branch 'master' into jenkins-pipelines
delvedor 4bfd37b
Updated reporting
delvedor c181e02
Pull latest image from docker hub
delvedor a09dfce
Added withGithubNotify
delvedor 761bf65
Randomize nodejs default version
delvedor 4c3ab31
Fix definition
delvedor 975797c
Moved Jenkinsfile
delvedor c2b9b69
Added daily trigger
delvedor eb09cb3
Use apm library
delvedor b332dc8
Added comment
delvedor b601c77
Added packer cache
delvedor f774243
Merge branch 'master' into jenkins-pipelines
delvedor 2b88f79
Updated multiline script and github notify steps
delvedor 76fbd29
Updated job definitions
delvedor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| #!/usr/bin/env groovy | ||
|
|
||
| @Library('apm@current') _ | ||
|
|
||
| def NODE_JS_VERSIONS = [8,10,12] | ||
| def nodeJsVersion = NODE_JS_VERSIONS[randomNumber(min: 0, max:2)] | ||
|
|
||
| pipeline { | ||
| agent { | ||
| label 'docker && immutable' | ||
| } | ||
|
|
||
| environment { | ||
| REPO = 'elasticsearch-js' | ||
| BASE_DIR = "src/github.com/elastic/${env.REPO}" | ||
| NODE_JS_DEFAULT_VERSION = "${nodeJsVersion}" | ||
| NODE_JS_VERSIONS = "${NODE_JS_VERSIONS.join(',')}" | ||
| HOME = "${env.WORKSPACE}" | ||
| npm_config_cache = 'npm-cache' | ||
| } | ||
|
|
||
| options { | ||
| timeout(time: 1, unit: 'HOURS') | ||
| buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30')) | ||
| timestamps() | ||
| ansiColor('xterm') | ||
| disableResume() | ||
| durabilityHint('PERFORMANCE_OPTIMIZED') | ||
| } | ||
|
|
||
| triggers { | ||
| issueCommentTrigger('(?i).*(?:jenkins\\W+)?run\\W+(?:the\\W+)?tests(?:\\W+please)?.*') | ||
| // changeRequest() will return true in case of a commit or a pr | ||
| // we will have a daily cron job only ofr branches that don't have an active pr | ||
| cron(changeRequest() ? '' : '@daily') | ||
| } | ||
|
|
||
| stages { | ||
| stage('Checkout') { | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| deleteDir() | ||
| gitCheckout(basedir: "${BASE_DIR}", githubNotifyFirstTimeContributor: false) | ||
| stash allowEmpty: true, name: 'source', useDefaultExcludes: false | ||
| } | ||
| } | ||
|
|
||
| stage('Install dependencies') { | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| deleteDir() | ||
| unstash 'source' | ||
| script { | ||
| buildDockerImage(image: "node:${env.NODE_JS_DEFAULT_VERSION}-alpine").inside(){ | ||
| dir("${BASE_DIR}"){ | ||
| sh(label: 'System info', script: 'node --version; npm --version') | ||
| sh(label: 'Install dependencies', script: 'npm install') | ||
| } | ||
| } | ||
| } | ||
| stash allowEmpty: true, name: 'source-dependencies', useDefaultExcludes: false | ||
| } | ||
| } | ||
|
|
||
| stage('License check') { | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| withGithubNotify(context: 'License check') { | ||
| deleteDir() | ||
| unstash 'source-dependencies' | ||
| script { | ||
| buildDockerImage(image: "node:${env.NODE_JS_DEFAULT_VERSION}-alpine").inside(){ | ||
| dir("${BASE_DIR}"){ | ||
| sh(label: 'Check production dependencies licenses', script: 'npm run license-checker') | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('Linter') { | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| withGithubNotify(context: 'Linter') { | ||
| deleteDir() | ||
| unstash 'source-dependencies' | ||
| script { | ||
| buildDockerImage(image: "node:${env.NODE_JS_DEFAULT_VERSION}-alpine").inside(){ | ||
| dir("${BASE_DIR}"){ | ||
| sh(label: 'Lint code with standardjs', script: 'npm run lint') | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('Unit test') { | ||
| failFast true | ||
| options { skipDefaultCheckout() } | ||
| steps { | ||
| withGithubNotify(context: 'Unit test') { | ||
| script { | ||
| def versions = env.NODE_JS_VERSIONS.split(',') | ||
| def parallelTasks = [:] | ||
| versions.each{ version -> | ||
| parallelTasks["Node.js v${version}"] = buildUnitTest(version: version) | ||
| } | ||
| parallel(parallelTasks) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('Integration test') { | ||
| failFast true | ||
| options { skipDefaultCheckout() } | ||
| parallel { | ||
| stage('OSS') { | ||
| agent { label 'docker && immutable' } | ||
| options { skipDefaultCheckout() } | ||
| environment { | ||
| TEST_ES_SERVER = 'http://elasticsearch:9200' | ||
| } | ||
| steps { | ||
| withGithubNotify(context: 'Integration test OSS') { | ||
| deleteDir() | ||
| unstash 'source-dependencies' | ||
| dir("${BASE_DIR}"){ | ||
| // Sometimes the docker registry fails and has random timeouts | ||
| // this block will retry a doker image 3 times before to fail. | ||
| retry(3) { | ||
| sleep randomNumber(min: 5, max: 10) | ||
| sh(label: 'Start Elasticsearch', script: './scripts/es-docker.sh --detach') | ||
| } | ||
| } | ||
| script { | ||
| buildDockerImage(fromDockerfile: true).inside('--network=elastic'){ | ||
| dir("${BASE_DIR}"){ | ||
| sh(label: 'Integration test', script: 'npm run test:integration | tee test-integration.tap') | ||
| sh(label: 'Generating test reporting', script: './node_modules/.bin/tap-mocha-reporter xunit < test-integration.tap > junit-integration.xml') | ||
| } | ||
| } | ||
| } | ||
| sh(label: 'Stop Elasticsearch', script: 'docker kill $(docker ps -q)') | ||
| junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/junit-*.xml") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| stage('xPack') { | ||
| agent { label 'docker && immutable' } | ||
| options { skipDefaultCheckout() } | ||
| environment { | ||
| TEST_ES_SERVER = 'https://elastic:changeme@elasticsearch:9200' | ||
| } | ||
| steps { | ||
| withGithubNotify(context: 'Integration test xPack') { | ||
| deleteDir() | ||
| unstash 'source-dependencies' | ||
| dir("${BASE_DIR}"){ | ||
| // Sometimes the docker registry fails and has random timeouts | ||
| // this block will retry a doker image 3 times before to fail. | ||
| retry(3) { | ||
| sleep randomNumber(min: 5, max: 10) | ||
| sh(label: 'Start Elasticsearch', script: './scripts/es-docker-platinum.sh --detach') | ||
| } | ||
| } | ||
| script { | ||
| buildDockerImage(fromDockerfile: true).inside('--network=elastic'){ | ||
| dir("${BASE_DIR}"){ | ||
| sh(label: 'Integration test', script: 'npm run test:integration | tee test-integration.tap') | ||
| sh(label: 'Generating test reporting', script: './node_modules/.bin/tap-mocha-reporter xunit < test-integration.tap > junit-integration.xml') | ||
| } | ||
| } | ||
| } | ||
| sh(label: 'Stop Elasticsearch', script: 'docker kill $(docker ps -q)') | ||
| junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/junit-*.xml") | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Sometimes the docker registry fails and has random timeouts | ||
| // this function will retry a doker image 3 times before to fail. | ||
| def buildDockerImage(args) { | ||
| def image | ||
| retry(3) { | ||
| sleep randomNumber(min: 5, max: 10) | ||
| if (args.fromDockerfile == true) { | ||
| image = docker.build('nodejs-image', "--build-arg NODE_JS_VERSION=${env.NODE_JS_DEFAULT_VERSION} ${BASE_DIR}/.ci/docker") | ||
| } else { | ||
| image = docker.image(args.image) | ||
| // make sure we have the latest available from Docker Hub | ||
| image.pull() | ||
| } | ||
| } | ||
| return image | ||
| } | ||
|
|
||
| def buildUnitTest(args) { | ||
| return { | ||
| node('docker && immutable') { | ||
| deleteDir() | ||
| unstash 'source' | ||
| script { | ||
| buildDockerImage(image: "node:${args.version}-alpine").inside(){ | ||
| dir("${BASE_DIR}"){ | ||
| sh(label: 'Install dependencies', script: 'npm install') | ||
| sh(label: 'Run unit test', script: 'npm run test:unit | tee test-unit.tap') | ||
| sh(label: 'Run behavior test', script: 'npm run test:behavior | tee test-behavior.tap') | ||
| sh(label: 'Run types test', script: 'npm run test:types') | ||
| sh(label: 'Generating test reporting', script: './node_modules/.bin/tap-mocha-reporter xunit < test-unit.tap > junit-unit.xml; ./node_modules/.bin/tap-mocha-reporter xunit < test-behavior.tap > junit-behavior.xml') | ||
| } | ||
| } | ||
| } | ||
| junit(allowEmptyResults: true, keepLongStdio: true, testResults: "${BASE_DIR}/**/junit-*.xml") | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ARG NODE_JS_VERSION=10 | ||
| FROM node:${NODE_JS_VERSION}-alpine | ||
|
|
||
| RUN apk --no-cache add git | ||
|
|
||
| # Create app directory | ||
| WORKDIR /usr/src/app | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| source /usr/local/bin/bash_standard_lib.sh | ||
|
|
||
| DOCKER_IMAGES="node:12-alpine | ||
| node:10-alpine | ||
| node:8-alpine | ||
| " | ||
|
|
||
| for di in ${DOCKER_IMAGES} | ||
| do | ||
| (retry 2 docker pull "${di}") || echo "Error pulling ${di} Docker image, we continue" | ||
| done | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️