Skip to content

Commit

Permalink
Automate the creation of release tags (opensearch-project#1666)
Browse files Browse the repository at this point in the history
* Automate the creation of release tag

Signed-off-by: Zelin Hao <[email protected]>
  • Loading branch information
zelinh authored Mar 7, 2022
1 parent 543ef57 commit 46c244b
Show file tree
Hide file tree
Showing 13 changed files with 580 additions and 2 deletions.
57 changes: 57 additions & 0 deletions jenkins/release-tag/release-tag.jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
lib = library(identifier: 'jenkins@20211123', retriever: legacySCM(scm))

pipeline {
options {
timeout(time: 2, unit: 'HOURS')
}
agent {
docker {
label 'Jenkins-Agent-al2-x64-c54xlarge-Docker-Host'
image 'opensearchstaging/ci-runner:centos7-x64-arm64-jdkmulti-node10.24.1-cypress6.9.1-20211130'
alwaysPull true
}
}
parameters {
string(
name: 'BUILD_ID',
description: 'Build ID of the distribution build manifest generated.',
trim: true
)
string(
name: 'VERSION',
description: 'Version of the distribution build manifest.',
trim: true
)
}
environment {
BUILD_MANIFEST = "builds/opensearch/manifest.yml"
}
stages {
stage('Create Release Tag') {
steps {
script {
manifest_path = "distribution-build-opensearch/${VERSION}/${BUILD_ID}/linux/x64/builds/opensearch/manifest.yml"
downloadFromS3(
destPath: "$WORKSPACE/$BUILD_MANIFEST",
bucket: "${ARTIFACT_BUCKET_NAME}",
path: "${manifest_path}",
force: true
)
echo "Distribution build manifest is downloaded to $BUILD_MANIFEST"
createReleaseTag(
buildManifest: "$BUILD_MANIFEST",
tagVersion: VERSION
)

}
}
}
}
post() {
always {
script {
postCleanup()
}
}
}
}
14 changes: 14 additions & 0 deletions src/jenkins/BuildManifest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,18 @@ class BuildManifest implements Serializable {
public String getMinArtifact() {
components.get(build.name.replace(' ','-'))?.artifacts?.get("dist")?.first()
}

public String getCommitId (String name) {
return this.components.get(name).commit_id
}

public ArrayList getNames() {
def componentsName = []
this.components.each{key, value -> componentsName.add(key)}
return componentsName
}

public String getRepo(String name) {
return this.components.get(name).repository
}
}
28 changes: 28 additions & 0 deletions tests/jenkins/TestCreateReleaseTag.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/


import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test

class TestCreateReleaseTag extends BuildPipelineTest {

@Before
void setUp() {

this.registerLibTester(new CreateReleaseTagLibTester('tests/data/opensearch-build-1.1.0.yml', '1.1.0'))
super.setUp()

}

@Test
void testCreateReleaseTag() {
super.testPipeline("tests/jenkins/jobs/CreateReleaseTag_Jenkinsfile")
}
}
43 changes: 43 additions & 0 deletions tests/jenkins/TestReleaseTagJob.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/


import jenkins.tests.BuildPipelineTest
import org.junit.Before
import org.junit.Test

class TestReleaseTagJob extends BuildPipelineTest {

@Before
void setUp() {

def buildManifest = 'tests/data/opensearch-build-1.1.0.yml'

def destPath = "${this.workspace}/${buildManifest}"

def artifactsPath = 'distribution-build-opensearch/1.1.0/123/linux/x64/builds/opensearch/manifest.yml'

def bucketName = 'job-s3-bucket-name'

this.registerLibTester(new DownloadFromS3LibTester(destPath, bucketName, artifactsPath, true))

this.registerLibTester(new CreateReleaseTagLibTester(buildManifest, '1.1.0'))

super.setUp()

// Variables for Release Tag Job
binding.setVariable('VERSION', '1.1.0')
binding.setVariable('BUILD_ID', '123')
binding.setVariable('ARTIFACT_BUCKET_NAME', bucketName)
binding.setVariable('BUILD_MANIFEST', buildManifest)

}

@Test
void ReleaseTag_test() {
super.testPipeline('jenkins/release-tag/release-tag.jenkinsfile',
'tests/jenkins/jenkinsjob-regression-files/release-tag/release-tag.jenkinsfile')
}
}

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion tests/jenkins/jobs/BuildManifest_Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ pipeline {
echo buildManifest.getUrl('https://ci.opensearch.org/ci/dbc', 'bundle-build', '1')
echo buildManifest.getArtifactUrl('https://ci.opensearch.org/ci/dbc', 'bundle-build', '1')
echo buildManifest.build.getPackageName()
echo buildManifest.components.getMinArtifact()
echo buildManifest.getMinArtifact()
echo buildManifest.getIndexFileRoot("distribution-build-opensearch")
echo buildManifest.getCommitId("OpenSearch")
echo buildManifest.getRepo("OpenSearch")
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/jenkins/jobs/BuildManifest_Jenkinsfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
BuildManifest_Jenkinsfile.echo(dist/opensearch-min-1.1.0-linux-x64.tar.gz)
BuildManifest.getIndexFileRoot(distribution-build-opensearch)
BuildManifest_Jenkinsfile.echo(distribution-build-opensearch/1.1.0)
BuildManifest.getCommitId(OpenSearch)
BuildManifest_Jenkinsfile.echo(b7334f49d530ffd1a3f7bd0e5832b9b2a9caa583)
BuildManifest.getRepo(OpenSearch)
BuildManifest_Jenkinsfile.echo(https://github.com/opensearch-project/OpenSearch.git)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ pipeline {
echo buildManifest.getArtifactRoot('bundle-build', '1')
echo buildManifest.getArtifactRootUrl('https://ci.opensearch.org/ci/dbc', 'bundle-build', '1')
echo buildManifest.build.getPackageName()
echo buildManifest.components.getMinArtifact()
echo buildManifest.getMinArtifact()
echo buildManifest.getCommitId("OpenSearch-Dashboards")
echo buildManifest.getRepo("OpenSearch-Dashboards")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@
BuildManifest_Jenkinsfile_component_no_artifact.echo(opensearch-dashboards-1.2.0-linux-x64.tar.gz)
BuildManifest.getMinArtifact()
BuildManifest_Jenkinsfile_component_no_artifact.echo(dist/opensearch-dashboards-min-1.2.0-linux-x64.tar.gz)
BuildManifest.getCommitId(OpenSearch-Dashboards)
BuildManifest_Jenkinsfile_component_no_artifact.echo(caf668e73304bac890f41c37cd6c3a41257cd289)
BuildManifest.getRepo(OpenSearch-Dashboards)
BuildManifest_Jenkinsfile_component_no_artifact.echo(https://github.com/opensearch-project/OpenSearch-Dashboards.git)
15 changes: 15 additions & 0 deletions tests/jenkins/jobs/CreateReleaseTag_Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pipeline {
agent none
stages {
stage('createTag') {
steps {
script {
createReleaseTag(
buildManifest: "tests/data/opensearch-build-1.1.0.yml",
tagVersion: "1.1.0"
)
}
}
}
}
}
Loading

0 comments on commit 46c244b

Please sign in to comment.