Skip to content

Commit

Permalink
Restore compatibility with Kubernetes pod agents (#774)
Browse files Browse the repository at this point in the history
By dropping detecting of execution inside container() step 

This reverts #766
  • Loading branch information
ljackiewicz authored Mar 22, 2024
1 parent a791a6d commit ebf07b2
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class WithMavenStepExecution2 extends GeneralNonBlockingStepExecution {
private transient FilePath tempBinDir;

/**
* Indicates if running on docker with <code>docker.image()</code> or <code>container()</code>
* Indicates if running on docker with <code>docker.image()</code>
*/
private boolean withContainer;

Expand Down Expand Up @@ -238,7 +238,7 @@ protected boolean doStart() throws Exception {
}

/**
* Detects if this step is running inside <code>docker.image()</code> or <code>container()</code>
* Detects if this step is running inside <code>docker.image()</code>
* <p>
* This has the following implications:
* <li>Tool installers do no work, as they install in the host, see:
Expand All @@ -247,24 +247,17 @@ protected boolean doStart() throws Exception {
* container running the <code>sh</code> command for maven This is due to the fact that <code>docker.image()</code> all it
* does is decorate the launcher and execute the command with a <code>docker run</code> which means that the inherited
* environment from the OS will be totally different eg: MAVEN_HOME, JAVA_HOME, PATH, etc.
* <li>Kubernetes' <code>container()</code> support is still in early stages, and environment variables might not be
* completely configured, depending on the version of the Jenkins Kubernetes plugin.
*
* @return true if running inside a container with <code>docker.image()</code> or <code>container()</code>
* @return true if running inside a container with <code>docker.image()</code>
* @see <a href=
* "https://github.com/jenkinsci/docker-workflow-plugin/blob/master/src/main/java/org/jenkinsci/plugins/docker/workflow/WithContainerStep.java">
* WithContainerStep</a> and <a href=
* "https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/ContainerStep.java">
* ContainerStep</a>
* WithContainerStep</a>
*/
private boolean detectWithContainer() throws IOException {
Launcher launcher1 = launcher;
while (launcher1 instanceof Launcher.DecoratedLauncher) {
String launcherClassName = launcher1.getClass().getName();
if (launcherClassName.contains("ContainerExecDecorator")) {
LOGGER.log(Level.FINE, "Step running within Kubernetes container(): {0}", launcherClassName);
return true;
}
// ToDo: add support for container() step (ContainerExecDecorator) from Kubernetes plugin
if (launcherClassName.contains("WithContainerStep")) {
LOGGER.log(Level.FINE, "Step running within docker.image(): {0}", launcherClassName);

Expand Down

0 comments on commit ebf07b2

Please sign in to comment.