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

Environment variables are not passed to cmake steps when running in pipeline withEnv

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      CMake plugin commands do not seem to pass environment to cmake command.

      withEnv(['CC=clang', 'CXX=clang++' {
        cmakeBuild(
          buildDir: 'build/debug',
          buildType: 'Debug',
          generator: 'Ninja',
          installation: 'InSearchPath',
        )
      }

       

      [debug] $ docker exec --workdir /var/lib/jenkins/workspace/job/build/debug 67363250bd775405c7cdf92b70a6d7a70dc136a48c93e350fea9cd12ba50d432 cmake -G Ninja -D CMAKE_BUILD_TYPE=Debug /var/lib/jenkins/workspace/job
      -- The C compiler identification is GNU 7.2.0
      -- The CXX compiler identification is GNU 7.2.0
      -- Check for working C compiler: /usr/sbin/cc
      -- Check for working C compiler: /usr/sbin/cc – works
      -- Detecting C compiler ABI info
      -- Detecting C compiler ABI info - done
      -- Detecting C compile features
      -- Detecting C compile features - done
      -- Check for working CXX compiler: /usr/sbin/c++
      -- Check for working CXX compiler: /usr/sbin/c++ – works
      -- Detecting CXX compiler ABI info
      -- Detecting CXX compiler ABI info - done
      -- Detecting CXX compile features
      -- Detecting CXX compile features - done

       

      Also, if CMake is installed in /usr/local/bin (and it works in sh step) the CMake builder plugin apparently does not find cmake binary:

      [debug] $ cmake -G Ninja -D CMAKE_BUILD_TYPE=Debug /Users/jenkins/workspace/job
      Cannot run program "cmake" (in directory "/Users/jenkins/workspace/job/build/debug"): error=2, No such file or directory

      In sh step which cmake prints /usr/local/bin/cmake and you can run cmake succesfully

        Attachments

          Activity

          Hide
          feliwir Stephan Vedder added a comment -

          Martin Weber the issue i was describing is that i can create a pipeline like this:

          pipeline {
              agent any
              environment { 
                  CC = 'clang'
              }
              stages {
                  stage('Example') {
                      environment { 
                          CC = clang 
                          CC = clang++
                      }
                      steps {
                          cmakeBuild(...)
                      }
                  }
              }
          }
          

          The cmake steps won't use any of the environment variables that were set in the environment block here

          Show
          feliwir Stephan Vedder added a comment - Martin Weber the issue i was describing is that i can create a pipeline like this: pipeline { agent any environment { CC = 'clang' } stages { stage( 'Example' ) { environment { CC = clang CC = clang++ } steps { cmakeBuild(...) } } } } The cmake steps won't use any of the environment variables that were set in the environment block here
          Hide
          15knots Martin Weber added a comment - - edited

          Stephan Vedder What does This does also not work refer to?
          If you feel this issue persists, please re-open and provide some more details.

          Show
          15knots Martin Weber added a comment - - edited Stephan Vedder What does This does also not work refer to? If you feel this issue persists, please re-open and provide some more details.
          Hide
          feliwir Stephan Vedder added a comment -

          This does also not work when using a declarative pipeline with an environment directive (https://jenkins.io/doc/book/pipeline/syntax/#environment)

          Show
          feliwir Stephan Vedder added a comment - This does also not work when using a declarative pipeline with an environment directive ( https://jenkins.io/doc/book/pipeline/syntax/#environment )
          Hide
          janneronkko Janne Rönkkö added a comment -

          The sh step contains only cmake invocation, i.e. it is like this:

          sh 'cmake --version'

          We are not building on the master as we use agents for building. /usr/local/bin is added to path using Node Properties (there is environment variable called PATH+LOCAL_BIN which has value /usr/local/bin).

          Also our master has /usr/local/bin in it's PATH

          Show
          janneronkko Janne Rönkkö added a comment - The sh step contains only cmake invocation, i.e. it is like this: sh 'cmake --version' We are not building on the master as we use agents for building. /usr/local/bin is added to path using Node Properties (there is environment variable called PATH+LOCAL_BIN which has value  /usr/local/bin ). Also our master has  /usr/local/bin in it's PATH
          Hide
          15knots Martin Weber added a comment -

          Also, if CMake is installed in /usr/local/bin (and it works in sh step) the CMake builder plugin apparently does not find cmake binary:

          The plugin directly invokes cmake, without any shell. So it will see only the environment variables of the jenkins master process or agent process.
          My guess is that your sh step adds /usr/local/bin to $PATH.
          On linux, processes started as a system process during boot inherit fewer environment variables than the processes started by a user`s login shell.
          AFAIK, a recent SUSE or RHEL does not have /usr/local/bin in $PATH by default.

          Could you check the Jenkins System Information page for the PATH variable?

          Show
          15knots Martin Weber added a comment - Also, if CMake is installed in /usr/local/bin (and it works in sh step) the CMake builder plugin apparently does not find cmake binary: The plugin directly invokes cmake, without any shell. So it will see only the environment variables of the jenkins master process or agent process. My guess is that your sh step adds /usr/local/bin to $PATH. On linux, processes started as a system process during boot inherit fewer environment variables than the processes started by a user`s login shell. AFAIK, a recent SUSE or RHEL does not have /usr/local/bin in $PATH by default. Could you check the Jenkins System Information page for the PATH variable?

            People

            • Assignee:
              15knots Martin Weber
              Reporter:
              janneronkko Janne Rönkkö
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: