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

withCredentials does not work with withEnv step inside container

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • pipeline
    • None

      The withCredentials step does not work inside a container when the withEnv step is used together.

      This is a snippet from the Jenkinsfile:

       

      def customImage = docker.build("regression-alpine", "-f ./test/Dockerfile.jenkins .")
      
              customImage.inside('-v $WORKSPACE:/logs -u root --privileged') {
                  withCredentials([string(credentialsId: 'my-credential', variable: 'MY_CREDENTIAL')]) {
                      withEnv(['ENV_VAR1=value1', 'ENV_VAR2=value2']) {
                          stage('Test operations') {
                              sh 'poetry install'
                              sh 'poetry run pytest -v --junitxml=results.xml test'
                          }
                      }
                  }
          }

       

      At some point in the code I get the environment variables. Those from the withEnv step work fine, but not the MY_CREDENTIAL from the withCredentials step.

      The error recorded in the log is:

       

      INTERNALERROR> Traceback (most recent call last):
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 264, in wrap_session
      INTERNALERROR>     config._do_configure()
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 995, in _do_configure
      INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 277, in call_historic
      INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
      INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
      INTERNALERROR>     return outcome.get_result()
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
      INTERNALERROR>     raise ex[1].with_traceback(ex[2])
      INTERNALERROR>   File "/root/.cache/pypoetry/virtualenvs/test-1jvIaqCb-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
      INTERNALERROR>     res = hook_impl.function(*args)
      INTERNALERROR>   File "/home/jenkinsci/jenkins/workspace/project/test-app/test/conftest.py", line 32, in pytest_configure
      INTERNALERROR>     test_data.MY_CREDENTIAL["name"] = extract_name(value)
      INTERNALERROR>   File "/home/jenkinsci/jenkins/workspace/project/test-app/test/conftest.py", line 49, in extract_name
      INTERNALERROR>     return re.search(r".*(?=\.)", value).group(0)
      INTERNALERROR> AttributeError: 'NoneType' object has no attribute 'group' 

       

      The Jenkins controller is version 2.346.1.

            Unassigned Unassigned
            m_sancho Marco Sanchotene
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: