Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-69520

Artifactory plugin doesn't recognize the environment variables in the selected container

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • artifactory-plugin
    • Jenkins 2.319.2
      Artifactory plugin 3.17.0
      Kubernetes plugin 3651.v908e7db_10d06

      The pipeline step rtMavenRun does not recognize then environment variables JAVA_HOME and MAVEN_HOME in the selected container when the executor is running in a Kubernetes pod with multiple containers and the selected container isn't the JNLP container.

      Couldn't find Maven home at /usr/share/maven on agent JNLP4-connect connection from 192.168.29.177/192.168.29.177:48396. This could be because this build is running inside a Docker container.

      When the variable isn't set in the JNLP container but just in the maven container then the step rtMavenRun fail.

      java.lang.RuntimeException: Couldn't find maven installation
      at org.jfrog.hudson.maven3.Maven3Builder.getMavenHome(Maven3Builder.java:234)
      at org.jfrog.hudson.maven3.Maven3Builder.perform(Maven3Builder.java:109)
      at org.jfrog.hudson.pipeline.common.executors.MavenExecutor.execute(MavenExecutor.java:72)
      at org.jfrog.hudson.pipeline.declarative.steps.maven.MavenStep$Execution.runStep(MavenStep.java:106)
      at org.jfrog.hudson.pipeline.declarative.steps.maven.MavenStep$Execution.runStep(MavenStep.java:91)
      at org.jfrog.hudson.pipeline.ArtifactorySynchronousNonBlockingStepExecution.run(ArtifactorySynchronousNonBlockingStepExecution.java:55)
      at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      at java.base/java.lang.Thread.run(Thread.java:829)

       

      The pod is defined outside of the Jenkins file

      apiVersion: v1
      kind: Pod
      spec:
        serviceAccountName: jenkins
        securityContext:
          runAsUser: 82046
        activeDeadlineSeconds: 1800
        containers:
          - name: jnlp
            env:
              - name: JAVA_HOME
                value: "/usr/lib/jvm/java-11-openjdk-11.0.15.0.9-2.el8_2.x86_64"
              - name: MAVEN_HOME
                value: "/usr/share/maven"
            image: "image-registry.openshift-image-registry.svc:5000/openshift/jenkins-agent-base:latest"
            resources:
              limits:
                cpu: 300m
                memory: 500Mi
              requests:
                cpu: 45m
                memory: 250Mi
          - name: maven
            env:
              - name: MAVEN_HOME
                value: "/usr/share/maven"
            image: "image-registry.openshift-image-registry.svc:5000/ci-mdm-ci/jenkins-maven-agent:latest"
            command:
              - cat
            tty: true
            resources:
              limits:
                cpu: 700m
                memory: 1500Mi
              requests:
                cpu: 80m
                memory: 750Mi
            volumeMounts:
              - mountPath: "/home/jenkins/.m2/repository"
                name: "maven"
                readOnly: false
              - mountPath: "/home/jenkins/.sonar"
                name: "sonar"
                readOnly: false
              - mountPath: "/home/jenkins/.m2"
                name: "maven-settings"

      Jenkinsfile

       

      pipeline {
          agent {
              kubernetes {
                  yamlFile 'pod.yaml'
              }
          }
          stages {
              stage('Maven Build') {
                  steps {
                      container('maven') {
                          rtServer (id: 'artifactory',  url: getArtifactoryURL())
                          rtMavenResolver(id: 'resolver', serverId: 'artifactory', releaseRepo: 'libs-release', snapshotRepo: 'libs-snapshot')
                          rtMavenRun(pom: 'pom.xml', goals: clean install, resolverId: 'resolver')
                      }
                  }
              }
          }
      }
      

       

       

            eyalbe Eyal Ben Moshe
            mi_ko Milan Konzal
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: