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]: CI pipeline #54

Merged
merged 12 commits into from
Jun 24, 2020
88 changes: 88 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

@Library('apm@current') _

pipeline {
agent { label 'linux && immutable' }
environment {
REPO = 'golang-crossbuild'
BASE_DIR = "src/github.com/elastic/${env.REPO}"
NOTIFY_TO = credentials('notify-to')
PIPELINE_LOG_LEVEL = 'INFO'
HOME = "${env.WORKSPACE}"
DOCKER_REGISTRY_SECRET = 'secret/apm-team/ci/docker-registry/prod'
REGISTRY = 'docker.elastic.co'
STAGING_IMAGE = "${env.REGISTRY}/observability-ci"
}
options {
timeout(time: 2, unit: 'HOURS')
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '20', daysToKeepStr: '30'))
timestamps()
ansiColor('xterm')
disableResume()
durabilityHint('PERFORMANCE_OPTIMIZED')
rateLimitBuilds(throttle: [count: 60, durationName: 'hour', userBoost: true])
quietPeriod(10)
}
triggers {
issueCommentTrigger('(?i).*jenkins\\W+run\\W+(?:the\\W+)?tests(?:\\W+please)?.*')
}
stages {
stage('Checkout') {
steps {
deleteDir()
gitCheckout(basedir: BASE_DIR)
stash allowEmpty: true, name: 'source', useDefaultExcludes: false
v1v marked this conversation as resolved.
Show resolved Hide resolved
}
}
stage('Build') {
steps {
withGithubNotify(context: 'Build') {
deleteDir()
unstash 'source'
dir(BASE_DIR){
sh 'make build'
}
}
}
}
stage('Staging') {
steps {
withGithubNotify(context: 'Staging') {
dir(BASE_DIR){
dockerLogin(secret: "${DOCKER_REGISTRY_SECRET}", registry: "${REGISTRY}")
withEnv( [ "REPOSITORY=${env.STAGING_IMAGE}" ] ) {
// It will use the already cached docker images that were created in the
// Build stage. But it's required to retag them with the staging repo.
sh 'make build'
sh(label: "push docker image to ${env.REPOSITORY}", script: 'make push')
}
}
}
}
}
stage('Release') {
when {
anyOf {
tag pattern: 'v\\d+\\.\\d+.*', comparator: 'REGEXP'
}
}
stages {
stage('Publish') {
steps {
withGithubNotify(context: 'Publish') {
dir(BASE_DIR){
dockerLogin(secret: "${DOCKER_REGISTRY_SECRET}", registry: "${REGISTRY}")
sh 'make push'
}
}
}
}
}
}
}
post {
always {
notifyBuildResult()
}
}
}
v1v marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion Makefile.common
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
REPOSITORY := docker.elastic.co/beats-dev
REPOSITORY ?= docker.elastic.co/beats-dev
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the only change in the code to be able to set the repository where the docker images can be pushed, by default as used to be, but as we will be using the staging stage, then this will help to generate docker images on a PR basis which can be consumed for testing purposes.

VCS_REF := $(shell git rev-parse HEAD)
VCS_URL := https://github.com/elastic/golang-crossbuild
BUILD_DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
Expand Down