Skip to content

Commit

Permalink
Fix detection if withMaven is executed within container() (#766)
Browse files Browse the repository at this point in the history
* Fix logging in detectWithContainer method

* Fix detection of builds run inside 'container' block

* Remove duplicated condition

* Keep changes made within JENKINS-53831

* Simplify launcherClassName checking of ContainerExecDecorator

* Fix logging info
  • Loading branch information
ljackiewicz authored Mar 6, 2024
1 parent 18876d1 commit e40d47e
Showing 1 changed file with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,6 @@ protected boolean doStart() throws Exception {

withContainer = detectWithContainer();

if (withContainer) {
console.trace("[withMaven] IMPORTANT \"withMaven(){...}\" step running within a Docker container. See ");
console.traceHyperlink(
"https://github.com/jenkinsci/pipeline-maven-plugin/blob/master/FAQ.adoc#how-to-use-the-pipeline-maven-plugin-with-docker",
"Pipeline Maven Plugin FAQ");
console.trace(" in case of problem.");
}

setupJDK();

// list of credentials injected by withMaven. They will be tracked and masked in the logs
Expand Down Expand Up @@ -265,19 +257,23 @@ protected boolean doStart() throws Exception {
* "https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerStep.java">
* ContainerStep</a>
*/
private boolean detectWithContainer() {
private boolean detectWithContainer() throws IOException {
Launcher launcher1 = launcher;
while (launcher1 instanceof Launcher.DecoratedLauncher) {
String launcherClassName = launcher1.getClass().getName();
if (launcherClassName.contains("org.csanchez.jenkins.plugins.kubernetes.pipeline.ContainerExecDecorator")) {
LOGGER.log(Level.FINE, "Step running within Kubernetes withContainer(): {1}", launcherClassName);
return false;
if (launcherClassName.contains("ContainerExecDecorator")) {
LOGGER.log(Level.FINE, "Step running within Kubernetes container(): {0}", launcherClassName);
return true;
}
if (launcherClassName.contains("WithContainerStep")) {
LOGGER.log(Level.FINE, "Step running within docker.image(): {1}", launcherClassName);
return true;
} else if (launcherClassName.contains("ContainerExecDecorator")) {
LOGGER.log(Level.FINE, "Step running within docker.image(): {1}", launcherClassName);
LOGGER.log(Level.FINE, "Step running within docker.image(): {0}", launcherClassName);

console.trace(
"[withMaven] IMPORTANT \"withMaven(){...}\" step running within a Docker container. See ");
console.traceHyperlink(
"https://github.com/jenkinsci/pipeline-maven-plugin/blob/master/FAQ.adoc#how-to-use-the-pipeline-maven-plugin-with-docker",
"Pipeline Maven Plugin FAQ");
console.trace(" in case of problem.");
return true;
}
launcher1 = ((Launcher.DecoratedLauncher) launcher1).getInner();
Expand Down

1 comment on commit e40d47e

@chrismathis
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this breaks my builds that use the kubernets plugin.
For k8s it probably did not matter if the tools got installed on the jnlp container or in the build container - since they share the workspace filesystem normally.

Please sign in to comment.