Skip to content

Commit 083d4f1

Browse files
authored
Remove stages related to tests from Jenkinsfile (#1147)
Remove stages related to tests from the Jenkinsfile and add a new stage to force update old Pull Requests. Updating the Pull Request will ensure that they are tested with the latest Buildkite pipeline changes.
1 parent d026daa commit 083d4f1

File tree

1 file changed

+11
-220
lines changed

1 file changed

+11
-220
lines changed

.ci/Jenkinsfile

Lines changed: 11 additions & 220 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@ pipeline {
1212
BASE_DIR="src/github.com/elastic/elastic-package"
1313
JOB_GIT_CREDENTIALS = "f6c7695a-671e-4f4f-a331-acdce44ff9ba"
1414
PIPELINE_LOG_LEVEL='INFO'
15-
AWS_ACCOUNT_SECRET = 'secret/observability-team/ci/elastic-observability-aws-account-auth'
1615
HOME = "${env.WORKSPACE}"
17-
KIND_VERSION = 'v0.17.0'
18-
K8S_VERSION = 'v1.26.0'
19-
JOB_GCS_BUCKET = 'fleet-ci-temp'
20-
JOB_GCS_BUCKET_INTERNAL = 'fleet-ci-temp-internal'
21-
JOB_GCS_CREDENTIALS = 'fleet-ci-gcs-plugin'
22-
JOB_GCS_EXT_CREDENTIALS = 'fleet-ci-gcs-plugin-file-credentials'
23-
ELASTIC_PACKAGE_GCP_SECRET = 'secret/observability-team/ci/service-account/elastic-package-gcp'
24-
ELASTIC_OBSERVABILITY_PROJECT_ID = 'elastic-observability'
16+
BUILDKITE_MERGE_COMMIT = "79ee1738578deac17f8f5caf8d925db6244ab6df"
2517
}
2618
options {
2719
timeout(time: 1, unit: 'HOURS')
@@ -54,63 +46,19 @@ pipeline {
5446
/**
5547
Check the source code.
5648
*/
57-
stage('Check static') {
49+
stage('Check it contains Buildkite pipeline') {
5850
steps {
5951
cleanup()
6052
dir("${BASE_DIR}"){
61-
withMageEnv(){
62-
sh(label: 'Check',script: 'make check-static')
63-
}
64-
}
65-
}
66-
}
67-
/**
68-
Run the unit tests suite
69-
*/
70-
stage('Unit tests') {
71-
steps {
72-
cleanup()
73-
dir("${BASE_DIR}"){
74-
withMageEnv(){
75-
sh(label: 'Check',script: 'make test-go-ci')
76-
}
77-
}
78-
}
79-
post {
80-
always {
81-
dir("${BASE_DIR}") {
82-
archiveArtifacts(allowEmptyArchive: true, artifacts: 'build/test-results/*.xml')
83-
junit(allowEmptyResults: false, keepLongStdio: true, testResults: "build/test-results/*.xml")
84-
stashCoverageReport()
85-
}
86-
}
87-
}
88-
}
89-
stage('Integration tests') {
90-
failFast true
91-
options { skipDefaultCheckout() }
92-
steps {
93-
withGithubNotify(context: 'Integration tests', tab: 'tests') {
94-
cleanup()
95-
dir("${BASE_DIR}") {
96-
script {
97-
def basicTasks = [
98-
'stack-command-default': generateTestCommandStage(command: 'test-stack-command-default', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*', 'build/elastic-stack-status/*/*']),
99-
'stack-command-oldest': generateTestCommandStage(command: 'test-stack-command-oldest', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*', 'build/elastic-stack-status/*/*']),
100-
'stack-command-7x': generateTestCommandStage(command: 'test-stack-command-7x', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*', 'build/elastic-stack-status/*/*']),
101-
'stack-command-86': generateTestCommandStage(command: 'test-stack-command-86', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*', 'build/elastic-stack-status/*/*']),
102-
'stack-command-8x': generateTestCommandStage(command: 'test-stack-command-8x', artifacts: ['build/elastic-stack-dump/stack/*/logs/*.log', 'build/elastic-stack-dump/stack/*/logs/fleet-server-internal/*', 'build/elastic-stack-status/*/*']),
103-
'check-packages-with-kind': generateTestCommandStage(command: 'test-check-packages-with-kind', artifacts: ['build/test-results/*.xml', 'build/kubectl-dump.txt', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true),
104-
'check-packages-other': generateTestCommandStage(command: 'test-check-packages-other', artifacts: ['build/test-results/*.xml', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true),
105-
'check-packages-with-custom-agent': generateTestCommandStage(command: 'test-check-packages-with-custom-agent', artifacts: ['build/test-results/*.xml', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: true),
106-
'check-packages-benchmarks': generateTestCommandStage(command: 'test-check-packages-benchmarks', artifacts: ['build/test-results/*.xml', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*'], junitArtifacts: true, publishCoverage: false),
107-
'build-zip': generateTestCommandStage(command: 'test-build-zip', artifacts: ['build/elastic-stack-dump/build-zip/logs/*.log', 'build/packages/*.sig']),
108-
'profiles-command': generateTestCommandStage(command: 'test-profiles-command')
109-
]
110-
111-
def checkSinglePackageTasks = generateTestCheckSinglePackageStage()
112-
def tasks = basicTasks + checkSinglePackageTasks
113-
parallel tasks
53+
script {
54+
githubEnv()
55+
r = sh(label: 'Check', returnStatus: true, script: '''
56+
echo "Base commit: ${GIT_BASE_COMMIT}"
57+
git log --format=%H "${GIT_BASE_COMMIT}" | grep "${BUILDKITE_MERGE_COMMIT}"
58+
''')
59+
if (r != 0) {
60+
echo("You should update your branch to include latest buildkite pipelines")
61+
sh(label: 'Exit', script: 'exit 1')
11462
}
11563
}
11664
}
@@ -120,9 +68,6 @@ pipeline {
12068
}
12169
}
12270
post {
123-
always {
124-
publishCoverageReports()
125-
}
12671
cleanup {
12772
notifyBuildResult(prComment: true)
12873
}
@@ -135,157 +80,3 @@ def cleanup(){
13580
}
13681
unstash 'source'
13782
}
138-
139-
def generateTestCheckSinglePackageStage(Map args = [:]) {
140-
def artifacts = ['build/test-results/*.xml', 'build/elastic-stack-dump/check-*/logs/*.log', 'build/elastic-stack-dump/check-*/logs/fleet-server-internal/*']
141-
142-
def integrations = [:]
143-
dir("test/packages/parallel") {
144-
// Include hack to skip temporary files with "@tmp" suffix.
145-
// For reference: https://issues.jenkins.io/browse/JENKINS-52750
146-
findFiles()?.findAll{ !it.name.endsWith('@tmp') }?.collect{ it.name }?.sort()?.each {
147-
integrations["check-package-${it}"] = {
148-
withNode(labels: "ubuntu-20 && immutable", sleepMax: 20, forceWorkspace: true) {
149-
cleanup()
150-
try {
151-
dir("${BASE_DIR}"){
152-
withMageEnv(){
153-
withCloudTestEnv() {
154-
sh(label: 'Install elastic-package',script: "make install")
155-
sh(label: 'Build elastic-package',script: "make PACKAGE_UNDER_TEST=${it} test-check-packages-parallel")
156-
}
157-
}
158-
}
159-
} finally {
160-
dir("${BASE_DIR}") {
161-
artifacts.each { artifact ->
162-
archiveArtifacts(allowEmptyArchive: true, artifacts: "${artifact}")
163-
}
164-
archiveArtifactsSafe("insecure-logs/${it}", "build/elastic-stack-dump/check-${it}/logs/elastic-agent-internal/*")
165-
archiveArtifactsSafe("insecure-logs/${it}/container-logs", "build/container-logs/*.log")
166-
167-
junit(allowEmptyResults: true, keepLongStdio: true, testResults: "build/test-results/*.xml")
168-
stashCoverageReport()
169-
}
170-
}
171-
}
172-
}
173-
}
174-
}
175-
return integrations
176-
}
177-
178-
def generateTestCommandStage(Map args = [:]){
179-
def command = args.get('command')
180-
def artifacts = args.get('artifacts') ? args.get('artifacts') : []
181-
def junitArtifacts = args.get('junitArtifacts') ? args.get('junitArtifacts') : false
182-
def publishCoverage = args.get('publishCoverage') ? args.get('publishCoverage') : false
183-
184-
return {
185-
withNode(labels: "ubuntu-20 && immutable", sleepMax: 20, forceWorkspace: true) {
186-
cleanup()
187-
try {
188-
dir("${BASE_DIR}"){
189-
withMageEnv(){
190-
withKubernetes() {
191-
withCloudTestEnv() {
192-
sh(label: 'Check',script: "make install ${command} check-git-clean")
193-
}
194-
}
195-
}
196-
}
197-
} finally {
198-
dir("${BASE_DIR}") {
199-
artifacts.each { artifact ->
200-
archiveArtifacts(allowEmptyArchive: true, artifacts: "${artifact}")
201-
}
202-
203-
if (junitArtifacts) {
204-
junit(allowEmptyResults: true,
205-
keepLongStdio: true,
206-
testResults: "build/test-results/*.xml")
207-
}
208-
209-
if (publishCoverage) {
210-
stashCoverageReport()
211-
}
212-
}
213-
}
214-
}
215-
}
216-
}
217-
218-
def getCoverageBucketURI() {
219-
return "gs://${JOB_GCS_BUCKET}/" + getCoveragePathPrefix()
220-
}
221-
222-
def getCoveragePathPrefix() {
223-
return "${env.JOB_NAME}-${env.BUILD_ID}/test-coverage/"
224-
}
225-
226-
def publishCoverageReports() {
227-
stage('Publish coverage reports') {
228-
dir("${BASE_DIR}") {
229-
def bucketUri = getCoverageBucketURI() + "*.xml"
230-
googleStorageDownload(bucketUri: bucketUri, credentialsId: "${JOB_GCS_CREDENTIALS}", localDirectory: 'build/test-coverage', pathPrefix: getCoveragePathPrefix())
231-
coverageReport('build/test-coverage')
232-
}
233-
}
234-
}
235-
236-
def stashCoverageReport() {
237-
r = sh(label: "isCoverageReportPresent", script: "ls build/test-coverage/*.xml", returnStatus: true)
238-
if (r != 0) {
239-
echo "isCoverageReportPresent: coverage files not found, report won't be stashed"
240-
return
241-
}
242-
243-
googleStorageUploadExt(bucket: getCoverageBucketURI(), credentialsId: "${JOB_GCS_EXT_CREDENTIALS}", pattern: "build/test-coverage/*.xml")
244-
}
245-
246-
def withKubernetes(Closure body) {
247-
retryWithSleep(retries: 2, seconds: 5, backoff: true) { sh(label: "Install kind", script: '''
248-
mkdir -p ${HOME}/bin
249-
curl -sSLo ${HOME}/bin/kind "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64"
250-
chmod +x ${HOME}/bin/kind
251-
kind version
252-
''') }
253-
retryWithSleep(retries: 2, seconds: 5, backoff: true) { sh(label: "Install kubectl", script: '''
254-
mkdir -p ${HOME}/bin
255-
curl -sSLo ${HOME}/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/${K8S_VERSION}/bin/linux/amd64/kubectl"
256-
chmod +x ${HOME}/bin/kubectl
257-
kubectl version --client
258-
''') }
259-
withEnv(["PATH+TOOLS=${HOME}/bin"]) {
260-
body()
261-
}
262-
}
263-
264-
def withCloudTestEnv(Closure body) {
265-
def maskedVars = []
266-
// GCP
267-
withGCPEnv(secret: env.ELASTIC_PACKAGE_GCP_SECRET) {
268-
maskedVars.add([var: 'GOOGLE_CREDENTIALS', password: readFile(file: env.GOOGLE_APPLICATION_CREDENTIALS)]);
269-
maskedVars.add([var: 'GCP_PROJECT_ID', password: env.ELASTIC_OBSERVABILITY_PROJECT_ID])
270-
}
271-
// Masking
272-
withEnvMask(vars: maskedVars) {
273-
withSecretVault(secret: "${AWS_ACCOUNT_SECRET}",
274-
data: ['access_key': 'AWS_ACCESS_KEY_ID', 'secret_key': 'AWS_SECRET_ACCESS_KEY']) {
275-
body()
276-
}
277-
}
278-
}
279-
280-
def archiveArtifactsSafe(remotePath, artifacts) {
281-
r = sh(label: "areArtifactsPresent", script: "ls ${artifacts}", returnStatus: true)
282-
if (r != 0) {
283-
echo "areArtifactsPresent: artifacts files not found, nothing will be archived"
284-
return
285-
}
286-
287-
googleStorageUploadExt(
288-
bucket: "gs://${JOB_GCS_BUCKET_INTERNAL}/${env.JOB_NAME}-${env.BUILD_ID}/${remotePath}",
289-
credentialsId: "${JOB_GCS_EXT_CREDENTIALS}",
290-
pattern: artifacts)
291-
}

0 commit comments

Comments
 (0)