Skip to content

Commit 2f55253

Browse files
committed
feat: WIP
1 parent 83ba353 commit 2f55253

2 files changed

Lines changed: 55 additions & 56 deletions

File tree

infra/jenkins/job_dsl.groovy

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -88,63 +88,15 @@ freeStyleJob('link-project') {
8888
8989
echo "Detected language: $LANG_DETECTED"
9090
echo "$LANG_DETECTED" > $WHANOS_DIR/detected_language.txt
91-
''')
92-
93-
systemGroovyCommand('''
94-
import javaposse.jobdsl.plugin.*
95-
import jenkins.model.*
96-
97-
def projectName = build.buildVariableResolver.resolve("PROJECT_NAME")
98-
def gitUrl = build.buildVariableResolver.resolve("GIT_URL")
99-
def language = new File("detected_language.txt").text.trim().toLowerCase()
100-
def baseImage = "whanos-${language}"
101-
102-
def dslScript = """
103-
folder('Projects') {
104-
displayName('Projects')
105-
description('Available projects in Whanos')
106-
}
107-
108-
freeStyleJob("Projects/${projectName}") {
109-
displayName("${projectName}")
110-
description("Linked project managed by Whanos")
111-
112-
scm {
113-
git {
114-
remote {
115-
url("${gitUrl}")
116-
credentials('${build.buildVariableResolver.resolve("GIT_CREDENTIALS_ID")}')
117-
}
118-
branch('*/main')
119-
}
120-
}
12191
122-
triggers {
123-
scm('* * * * *') // every minute
124-
}
125-
126-
steps {
127-
shell("echo Building ${projectName} using ${baseImage}")
128-
shell("docker build -t ${projectName}:${language} --build-arg BASE_IMAGE=${baseImage} .")
129-
shell('\'\'\'
130-
#!/bin/bash
131-
set -e
132-
if [ -f whanos.yml ]; then
133-
echo "Deploying \${projectName} to Kubernetes..."
134-
kubectl apply -f whanos.yml
135-
else
136-
echo "No whanos.yml found, skipping deployment."
137-
fi
138-
\'\'\')
139-
}
140-
}
141-
"""
142-
143-
def dsl = new ExecuteDslScripts()
144-
dsl.scriptText = dslScript
145-
dsl.ignoreExisting = false
146-
dsl.removeAction = javaposse.jobdsl.plugin.RemovedJobAction.IGNORE
147-
dsl.run()
92+
# Copy DSL script to workspace
93+
ls -laR $WHANOS_DIR/infra/jenkins
94+
cp $WHANOS_DIR/infra/jenkins/project_job.groovy $WORKSPACE/project_job.groovy
14895
''')
96+
dsl {
97+
external("project_job.groovy")
98+
additionalClasspath("project_job.groovy/lives")
99+
ignoreExisting(false)
100+
}
149101
}
150102
}

infra/jenkins/project_job.groovy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
def String projectName = binding.variables['PROJECT_NAME']
2+
def String gitUrl = binding.variables['GIT_URL']
3+
def String credentialsId = binding.variables['GIT_CREDENTIALS_ID']
4+
def File languageFile = new File("${WORKSPACE}/detected_language.txt")
5+
def String language = languageFile.text.trim().toLowerCase()
6+
def String baseImage = "whanos-${language}"
7+
8+
folder('Projects') {
9+
displayName('Projects')
10+
description('Available projects in Whanos')
11+
}
12+
13+
freeStyleJob("Projects/${projectName}") {
14+
displayName("${projectName}")
15+
description('Linked project managed by Whanos')
16+
17+
scm {
18+
git {
19+
remote {
20+
url("${gitUrl}")
21+
if (credentialsId) {
22+
credentials(credentialsId)
23+
}
24+
}
25+
branch('*/main')
26+
}
27+
}
28+
29+
triggers {
30+
scm('* * * * *') // every minute
31+
}
32+
33+
steps {
34+
shell("echo Building ${projectName} using ${baseImage}")
35+
shell("docker build -t ${projectName}:${language} --build-arg BASE_IMAGE=${baseImage} .")
36+
shell("""
37+
#!/bin/bash
38+
set -e
39+
// if [ -f whanos.yml ]; then
40+
// echo "Deploying ${projectName} to Kubernetes..."
41+
// kubectl apply -f whanos.yml
42+
// else
43+
// echo "No whanos.yml found, skipping deployment."
44+
// fi
45+
""")
46+
}
47+
}

0 commit comments

Comments
 (0)