Skip to content

Commit 5a12b1f

Browse files
authored
Update linux samples for PSA "restricted" (#1574)
1 parent f5b83f1 commit 5a12b1f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/samples/declarative.groovy

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ spec:
2121
- sleep
2222
args:
2323
- infinity
24+
securityContext:
25+
# ubuntu runs as root by default, it is recommended or even mandatory in some environments (such as pod security admission "restricted") to run as a non-root user.
26+
runAsUser: 1000
2427
'''
2528
// Can also wrap individual steps:
2629
// container('shell') {

src/main/resources/org/csanchez/jenkins/plugins/kubernetes/pipeline/samples/maven.groovy

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ spec:
1313
- sleep
1414
args:
1515
- infinity
16+
securityContext:
17+
# maven runs as root by default, it is recommended or even mandatory in some environments (such as pod security admission "restricted") to run as a non-root user.
18+
runAsUser: 1000
1619
''') {
1720
retry(count: 2, conditions: [kubernetesAgent(), nonresumable()]) {
1821
node(POD_LABEL) {
@@ -28,22 +31,21 @@ spec:
2831
<plugin>
2932
<groupId>org.apache.maven.plugins</groupId>
3033
<artifactId>maven-surefire-plugin</artifactId>
31-
<version>2.18.1</version>
34+
<version>3.2.5</version>
3235
</plugin>
3336
</plugins>
3437
</build>
3538
<dependencies>
3639
<dependency>
3740
<groupId>junit</groupId>
3841
<artifactId>junit</artifactId>
39-
<version>4.12</version>
42+
<version>4.13.2</version>
4043
<scope>test</scope>
4144
</dependency>
4245
</dependencies>
4346
<properties>
4447
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
45-
<maven.compiler.source>1.8</maven.compiler.source>
46-
<maven.compiler.target>1.8</maven.compiler.target>
48+
<maven.compiler.release>17</maven.compiler.release>
4749
</properties>
4850
</project>
4951
'''
@@ -55,7 +57,8 @@ public class SomeTest {
5557
}
5658
'''
5759
container('maven') {
58-
sh 'mvn -B -ntp -Dmaven.test.failure.ignore verify'
60+
// Maven needs write access to $HOME/.m2, which it doesn't have in the maven image because only root is a real user.
61+
sh 'HOME=$WORKSPACE_TMP/maven mvn -B -ntp -Dmaven.test.failure.ignore verify'
5962
}
6063
junit '**/target/surefire-reports/TEST-*.xml'
6164
archiveArtifacts '**/target/*.jar'

0 commit comments

Comments
 (0)