-
Notifications
You must be signed in to change notification settings - Fork 274
/
release-branch.jenkinsfile
106 lines (98 loc) · 4.05 KB
/
release-branch.jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* Copyright OpenSearch Contributors
* 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.
*/
lib = library(identifier: '[email protected]', retriever: modernSCM([
$class: 'GitSCMSource',
remote: 'https://github.com/opensearch-project/opensearch-build-libraries.git',
]))
pipeline {
options {
timeout(time: 1, unit: 'HOURS')
}
agent {
docker {
label 'Jenkins-Agent-AL2023-X64-C54xlarge-Docker-Host'
image 'opensearchstaging/ci-runner:ci-runner-centos7-opensearch-build-v3'
registryUrl 'https://public.ecr.aws/'
alwaysPull true
}
}
parameters {
string(
name: 'MANIFEST_FILE',
description: "Provide either Build Manifest url's or path to manifest files separated by space for branch creation.",
trim: true
)
string(
name: 'SOURCE_BRANCH',
description: 'Target branch is created from this source branch.',
trim: true
)
string(
name: 'TARGET_BRANCH',
description: 'Provide name of the target branch that needs to be created.',
trim: true
)
}
environment {
MANIFEST_OBJ = null
BUILD_MANIFEST = 'build-manifest.yml'
}
stages {
stage('Create Release Branch') {
steps {
script {
if (!(MANIFEST_FILE && SOURCE_BRANCH && TARGET_BRANCH)) {
error('Required parameters are missing. Please provide the mandatory arguments MANIFEST_FILE, SOURCE_BRANCH and TARGET_BRANCH')
}
def manifestList = MANIFEST_FILE.trim().split(' ') as List
withCredentials([usernamePassword(credentialsId: "jenkins-github-bot-token", usernameVariable: 'GITHUB_USER', passwordVariable: 'GITHUB_TOKEN')]) {
for (manifest in manifestList) {
if (manifest.contains("builds")) {
downloadBuildManifest(
url: manifest,
path: BUILD_MANIFEST
)
MANIFEST_OBJ = lib.jenkins.BuildManifest.new(readYaml(file: BUILD_MANIFEST))
}
else {
MANIFEST_OBJ = lib.jenkins.InputManifest.new(readYaml(file: "manifests/${manifest}"))
}
componentNames = MANIFEST_OBJ.getNames()
for (component in componentNames) {
repoUrl = MANIFEST_OBJ.getRepo(component)
def branchExists = sh(
script: "git ls-remote ${repoUrl} ${TARGET_BRANCH}",
returnStdout: true
)
if (branchExists == "") {
def push_url = "https://$GITHUB_TOKEN@" + repoUrl.minus('https://')
dir(component) {
checkout([$class: 'GitSCM', branches: [[name: SOURCE_BRANCH]], userRemoteConfigs: [[url: repoUrl]]])
sh "git checkout -b $TARGET_BRANCH"
sh "git push $push_url $TARGET_BRANCH"
}
}
else {
echo "Branch already exists, skipping branch creation for the repo $repoUrl"
}
}
}
}
}
}
}
}
post() {
always {
script {
postCleanup()
}
}
}
}