Skip to content

Commit 8319e99

Browse files
committed
Adds Jenkinsfile for testing
1 parent ce7de89 commit 8319e99

1 file changed

Lines changed: 136 additions & 0 deletions

File tree

Jenkinsfile

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#!/usr/bin/env groovy
2+
@Library('pipeline@v2-stable')
3+
4+
import pipeline.fastly.kubernetes.jenkins.Constants
5+
import pipeline.fastly.github.Repo
6+
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
7+
8+
import static pipeline.fastly.github.Repo.CommitStatus
9+
10+
final def BUILD_TIMEOUT = 120
11+
final def NODELABEL = 'docker-build'
12+
final def RELEASE_BRANCH = 'main'
13+
14+
def buildResources = [resourceRequestMemory: '92Gi', resourceLimitMemory: '92Gi', resourceRequestCpu: '20000m', resourceLimitCpu: '20000m']
15+
def releaseBranches = [RELEASE_BRANCH, 'origin/' + RELEASE_BRANCH]
16+
def cache = true
17+
def cleanMergedRefs = false
18+
def pushDeb = false
19+
def pushImage = false
20+
def namedBuild = ''
21+
def tagName = null
22+
def slackChannel = null
23+
def emailToSlack = [
24+
'jkarneges@fastly.com': '@jkarneges',
25+
'ricky.hosfelt@fastly.com': '@Ricky',
26+
'serra.abak@fastly.com': '@Serra',
27+
]
28+
29+
def configureGitCreds() {
30+
withCredentials([string(credentialsId: Constants.GITHUB_OAUTH_CREDENTIALS, variable: 'GITHUB_TOKEN')]) {
31+
// With native GITHUB_TOKEN support we want to incorporate here https://github.com/fastly/xqd_rel_notes/issues/5
32+
// we don't need to create that config file
33+
sh(script: """
34+
mkdir ~/.ssh && ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
35+
git config --global user.email jenkins@secretcdn.net
36+
git config --global user.name jenkins
37+
mkdir ~/.config && cat <<'EOF' >~/.config/hub
38+
github.com:
39+
- user: jenkins
40+
oauth_token: ${GITHUB_TOKEN}
41+
protocol: https
42+
EOF
43+
""")
44+
}
45+
}
46+
47+
// Ignore TAG push events from GitHub, only branches built
48+
if (params.ref.contains('refs/tags/')) {
49+
currentBuild.result = 'ABORTED'
50+
currentBuild.description = 'Triggered by a TAG, ignoring ...'
51+
return
52+
}
53+
54+
String getCleanedUpBuildRef() {
55+
String ref = getBuildRef().name
56+
def match = (ref =~ /^origin\/(.*)/)
57+
if (match) {
58+
ref = match[0][1]
59+
}
60+
return ref
61+
}
62+
63+
String ref = getCleanedUpBuildRef()
64+
if (ref in releaseBranches) {
65+
pushDeb = true
66+
pushImage = true
67+
cache = false
68+
cleanMergedRefs = true
69+
tagName = 'jenkins/release'
70+
slackChannel = '#fanout-eng'
71+
} else if (ref =~ /^.*\/jenkins$/) {
72+
pushDeb = true
73+
cache = false
74+
namedBuild = ref.replaceAll('/jenkins', '').replaceAll('/', '-')
75+
slackChannel = emailToSlack[params.author_email]
76+
tagName = 'jenkins/named'
77+
} else if (ref =~ /^.*-stable$/) {
78+
pushDeb = true
79+
cache = false
80+
namedBuild = ref.replaceAll('-stable', '').replaceAll('/', '-')
81+
slackChannel = emailToSlack[params.author_email]
82+
tagName = 'jenkins/stable'
83+
} else {
84+
namedBuild = ref.replaceAll('/', '-')
85+
}
86+
87+
fastlyPipeline(script: this, buildTimeout: BUILD_TIMEOUT, ignoreTags: true, slackChannel: slackChannel) {
88+
getNode(label: NODELABEL, resources: buildResources) {
89+
def tmpDir = pwd(tmp: true)
90+
checkoutWithSubmodules scm
91+
def v = readFile file: './fastly-build/VERSION'
92+
def package_version = "${v.trim()}.${env.BUILD_NUMBER}"
93+
if (namedBuild) {
94+
package_version = "0.${package_version}-${namedBuild}"
95+
}
96+
97+
stage('Build') {
98+
sshagent(credentials: [Constants.GITHUB_SSHKEY_CREDENTIAL], socketPath:"${tmpDir}/agent.socket") {
99+
def buildContainerConfig = [
100+
dockerFile: 'Dockerfile',
101+
imageName: 'fastly/pushpin',
102+
pushImage: pushImage,
103+
cache: cache,
104+
additionalBuildArgs: [
105+
"DESTDIR=${env.WORKSPACE}",
106+
"PKG_VERSION=${package_version}",
107+
"SSH_AUTH_SOCK=${env.SSH_AUTH_SOCK}"
108+
]
109+
]
110+
fastlyDockerBuild(script: this, containers: [buildContainerConfig], checkout: false, loggerVerbosity: 'info')
111+
}
112+
}
113+
114+
if (pushDeb) {
115+
stage('Push Packages to APT') {
116+
fastlyAptPush(script: this, path: env.WORKSPACE)
117+
if (slackChannel) {
118+
slackSend color: null, message: "Package `fst-pushpin` version `${package_version}` uploaded.", channel: slackChannel
119+
}
120+
}
121+
}
122+
123+
if (tagName) {
124+
tagName = "${tagName}-${env.BUILD_NUMBER}-${params.commit.take(7)}"
125+
stage('Tag Commit') {
126+
tagCommit(tag: tagName)
127+
}
128+
}
129+
130+
if (cleanMergedRefs) {
131+
stage('Cleanup Merged Refs') {
132+
cleanupMergedBranches(script: this, masterBranch: RELEASE_BRANCH)
133+
}
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)