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

Since 2.2.6, environment variables are not expanded in git publisher

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • git-plugin
    • Jenkins: 1.580
      Git Plugin 2.2.6 (before update 2.2.5)
      All plugins up to date (21. September)

      Since 2.2.6 ssh credentials on git push seems to have a problem.
      When i revert back to 2.2.5 everything works as expected.
      I'm using jenkins credential with a ssh key.
      Don't know if that has something to say, but I'm using env var's to set the git url, and in the failing log it's not resolved. But I guess the error prints it before the resolution, because the connection itself seems to work, just not the authentication.
      I attached a log success.txt (with version 2.2.5) and a failing.txt (version 2.2.6). The only difference is that i reverted the plugin to 2.2.5 and everything worked again.
      let me know if you need more information. But maybe so find the problem due the recent changes.

        1. config.xml
          3 kB
        2. config.xml
          5 kB
        3. failing.txt
          5 kB
        4. success.txt
          4 kB

          [JENKINS-24786] Since 2.2.6, environment variables are not expanded in git publisher

          I just rolled back to 2.2.4 because of this issue. It is confirmed working in 2.2.4.

          Carlos Alexandre added a comment - I just rolled back to 2.2.4 because of this issue. It is confirmed working in 2.2.4.

          Code changed in jenkins
          User: Mark Waite
          Path:
          src/test/java/hudson/plugins/git/GitPublisherTest.java
          http://jenkins-ci.org/commit/git-plugin/55b0fd8404dec9b10bcfe52865e93fdc9845c836
          Log:
          Add tests of GitPublisher honoring env values

          Attempting to duplicate JENKINS-24786 from an automated test. Does not
          duplicate the bug. Shows that GitPublisher honors some environment
          variables.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/test/java/hudson/plugins/git/GitPublisherTest.java http://jenkins-ci.org/commit/git-plugin/55b0fd8404dec9b10bcfe52865e93fdc9845c836 Log: Add tests of GitPublisher honoring env values Attempting to duplicate JENKINS-24786 from an automated test. Does not duplicate the bug. Shows that GitPublisher honors some environment variables.

          Code changed in jenkins
          User: Mark Waite
          Path:
          src/test/java/hudson/plugins/git/GitPublisherTest.java
          http://jenkins-ci.org/commit/git-plugin/0814b694072509c3a3f49be33805cdb97075eba2
          Log:
          Add tests of GitPublisher honoring env values

          Attempting to duplicate JENKINS-24786 from an automated test. Does not
          duplicate the bug. Shows that GitPublisher honors some environment
          variables.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Mark Waite Path: src/test/java/hudson/plugins/git/GitPublisherTest.java http://jenkins-ci.org/commit/git-plugin/0814b694072509c3a3f49be33805cdb97075eba2 Log: Add tests of GitPublisher honoring env values Attempting to duplicate JENKINS-24786 from an automated test. Does not duplicate the bug. Shows that GitPublisher honors some environment variables.

          Carlos Alexandre added a comment - - edited

          Hey there Mark,
          Any news on this issue? Today I updated to the latest 2.3 version..i was forced to rollback once again due to this issue :/

          One thing I noted is that the GitPublisher only fails to expand a variable that is used in the Repository Url.
          If you use it on any other field, such as GitTag name or something similar, everything works as expected.

          Jenkins Core: 1.580.2
          Git Plugin version: 2.3.x

          Carlos Alexandre added a comment - - edited Hey there Mark, Any news on this issue? Today I updated to the latest 2.3 version..i was forced to rollback once again due to this issue :/ One thing I noted is that the GitPublisher only fails to expand a variable that is used in the Repository Url. If you use it on any other field, such as GitTag name or something similar, everything works as expected. Jenkins Core: 1.580.2 Git Plugin version: 2.3.x

          Mark Waite added a comment -

          I have hit a wall on the fix. My attempts to find a way to retain the other fixes included in 2.2.6 and fix this bug have failed. I'd love to have other eyes on the code, or alternative ways to implement the 2.2.6 fix which introduced the problem.

          Mark Waite added a comment - I have hit a wall on the fix. My attempts to find a way to retain the other fixes included in 2.2.6 and fix this bug have failed. I'd love to have other eyes on the code, or alternative ways to implement the 2.2.6 fix which introduced the problem.

          Daniel Figus added a comment -

          Hi Mark,

          I also ran into the issue and had a look into the code. I try to summarize what I already found out - I hope this helps:

          As the fetch is working I focused on analyzing the differences between the fetch and the push. As far as I understood the code the GitSCM holds the remote repository without expanded environment variables and expands them right before the fetch (https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L915). This step is is missing in the GitPublisher where the specified remote repository is retrieved from the gitSCM (https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitPublisher.java#L318). As this issue is urgent for our production I already started to prepare a test and fix for this issue. My naive approach would be simply do the same thing as GitSCM.getParamExpandedRepos() does right where the push command is created and executed. But as you wrote that you hit a wall here I'm a bit unconfident. Could you please share your concerns? I would need some more days to prepare a fix for a pull request but so far my first tests looked promising.

          Daniel Figus added a comment - Hi Mark, I also ran into the issue and had a look into the code. I try to summarize what I already found out - I hope this helps: As the fetch is working I focused on analyzing the differences between the fetch and the push. As far as I understood the code the GitSCM holds the remote repository without expanded environment variables and expands them right before the fetch ( https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitSCM.java#L915 ). This step is is missing in the GitPublisher where the specified remote repository is retrieved from the gitSCM ( https://github.com/jenkinsci/git-plugin/blob/master/src/main/java/hudson/plugins/git/GitPublisher.java#L318 ). As this issue is urgent for our production I already started to prepare a test and fix for this issue. My naive approach would be simply do the same thing as GitSCM.getParamExpandedRepos() does right where the push command is created and executed. But as you wrote that you hit a wall here I'm a bit unconfident. Could you please share your concerns? I would need some more days to prepare a fix for a pull request but so far my first tests looked promising.

          Mark Waite added a comment -

          goddi Your approach sounds promising. I hit a wall when I couldn't construct a set of tests which gave me enough confidence that I'd solved the problem without critically damaging something else.

          Since you're a directly involved user, you'll be able to test drive your changes in your own environment. A pull request from you will then allow me and/or Nicolas (or others) to review your changes in depth.

          Mark Waite added a comment - goddi Your approach sounds promising. I hit a wall when I couldn't construct a set of tests which gave me enough confidence that I'd solved the problem without critically damaging something else. Since you're a directly involved user, you'll be able to test drive your changes in your own environment. A pull request from you will then allow me and/or Nicolas (or others) to review your changes in depth.

          Daniel Figus added a comment -

          Created pull request 283 containing fix and tests. The updated git-plugin runs in our production jenkins without issues. Could you please review and provide feedback?

          Daniel Figus added a comment - Created pull request 283 containing fix and tests. The updated git-plugin runs in our production jenkins without issues. Could you please review and provide feedback?

          Code changed in jenkins
          User: Daniel Figus
          Path:
          src/main/java/hudson/plugins/git/GitPublisher.java
          src/main/java/hudson/plugins/git/GitSCM.java
          src/test/java/hudson/plugins/git/GitPublisherTest.java
          http://jenkins-ci.org/commit/git-plugin/f841caf3c2483532aad9feb20d2f3fac9722a878
          Log:
          JENKINS-24786 Environment variables are not expanded in git publisher

          Fix: Git publisher fails if remote repository configuration contains
          environment variables

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Daniel Figus Path: src/main/java/hudson/plugins/git/GitPublisher.java src/main/java/hudson/plugins/git/GitSCM.java src/test/java/hudson/plugins/git/GitPublisherTest.java http://jenkins-ci.org/commit/git-plugin/f841caf3c2483532aad9feb20d2f3fac9722a878 Log: JENKINS-24786 Environment variables are not expanded in git publisher Fix: Git publisher fails if remote repository configuration contains environment variables

          Mark Waite added a comment -

          The change from goddi has been rebased into the git plugin main line and will be available in git plugin 2.3.3 and later.

          Mark Waite added a comment - The change from goddi has been rebased into the git plugin main line and will be available in git plugin 2.3.3 and later.

            markewaite Mark Waite
            spali Thomas Spalinger
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: