{"action":"created","comment":{"url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/comments/66641795","id":66641795,"diff_hunk":"@@ -218,9 +217,16 @@ public void resolveVars(Map<String, String> variables, Map<String, String> env)\n             int previousNbUnresolvedVar = nbUnresolvedVar;\n             nbUnresolvedVar = 0;\n             for (Map.Entry<String, String> entry : variables.entrySet()) {\n-                String value = Util.replaceMacro(entry.getValue(), variables);\n-                entry.setValue(value);\n-                if (isUnresolvedVar(value)) {\n+                String key = entry.getKey();\n+                String value = entry.getValue();\n+                Map<String, String> resolveVariables = new HashMap<String, String>(variables);\n+                // avoid self reference expansion\n+                // FOO=$FOO-X -> FOO=$FOO-X-X -> FOO=$FOO-X-X-X etc.\n+                resolveVariables.remove(key);\n+                String newValue = Util.replaceMacro(value, resolveVariables);\n+                entry.setValue(newValue);\n+                boolean variableChanged = !newValue.equals(value);\n+                if (variableChanged && isUnresolvedVar(newValue)) {","path":"src/main/java/org/jenkinsci/plugins/envinject/service/EnvInjectEnvVars.java","position":24,"original_position":24,"commit_id":"33b741e90856a0afb9dbb712790dc937c71ae37f","original_commit_id":"33b741e90856a0afb9dbb712790dc937c71ae37f","user":{"login":"oleg-nenashev","id":3000480,"avatar_url":"https://avatars.githubusercontent.com/u/3000480?v=3","gravatar_id":"","url":"https://api.github.com/users/oleg-nenashev","html_url":"https://github.com/oleg-nenashev","followers_url":"https://api.github.com/users/oleg-nenashev/followers","following_url":"https://api.github.com/users/oleg-nenashev/following{/other_user}","gists_url":"https://api.github.com/users/oleg-nenashev/gists{/gist_id}","starred_url":"https://api.github.com/users/oleg-nenashev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oleg-nenashev/subscriptions","organizations_url":"https://api.github.com/users/oleg-nenashev/orgs","repos_url":"https://api.github.com/users/oleg-nenashev/repos","events_url":"https://api.github.com/users/oleg-nenashev/events{/privacy}","received_events_url":"https://api.github.com/users/oleg-nenashev/received_events","type":"User","site_admin":false},"body":"Are you sure that <code> variableChanged</code> is required here. For me it seems the counter won't be incremented properly if there is unresolved variables","created_at":"2016-06-10T16:24:02Z","updated_at":"2016-06-10T16:24:02Z","html_url":"https://github.com/jenkinsci/envinject-plugin/pull/90#discussion_r66641795","pull_request_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90","_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/comments/66641795"},"html":{"href":"https://github.com/jenkinsci/envinject-plugin/pull/90#discussion_r66641795"},"pull_request":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90"}}},"pull_request":{"url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90","id":70204421,"html_url":"https://github.com/jenkinsci/envinject-plugin/pull/90","diff_url":"https://github.com/jenkinsci/envinject-plugin/pull/90.diff","patch_url":"https://github.com/jenkinsci/envinject-plugin/pull/90.patch","issue_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues/90","number":90,"state":"open","locked":false,"title":"JENKINS-30467 support common cases of recursive variables","user":{"login":"XN137","id":1204398,"avatar_url":"https://avatars.githubusercontent.com/u/1204398?v=3","gravatar_id":"","url":"https://api.github.com/users/XN137","html_url":"https://github.com/XN137","followers_url":"https://api.github.com/users/XN137/followers","following_url":"https://api.github.com/users/XN137/following{/other_user}","gists_url":"https://api.github.com/users/XN137/gists{/gist_id}","starred_url":"https://api.github.com/users/XN137/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/XN137/subscriptions","organizations_url":"https://api.github.com/users/XN137/orgs","repos_url":"https://api.github.com/users/XN137/repos","events_url":"https://api.github.com/users/XN137/events{/privacy}","received_events_url":"https://api.github.com/users/XN137/received_events","type":"User","site_admin":false},"body":"on a matrix job we had something like this line in \"Properties Content\":\r\n`PATH=$WORKSPACE/git_checkout/bin:${PATH}`\r\n\r\nit expanded recursively (`WORKSPACE` being quite long already for matrix runners) and `PATH` grew very large and I think it caused build failures later, where calling bash failed with:\r\n`Argument list too long`\r\n\r\nduplicate issues: JENKINS-30446, JENKINS-30445, JENKINS-30444\r\n\r\nsimilar PR: #73 \r\n\r\nRegarding changes in `PropertiesVariablesRetriever`:\r\nthis logic should probably be re-used more often across the whole code base instead of plain `putAll`, which just overwrites values.\r\nCurrently there are still many inconsistencies regarding referencing previously defined variables (see comment in Test `injectTextExtendSysEnvVar` for an example) but fixing all those issues is outside of the scope of this PR.\r\n\r\nI adjusted `PropertiesGetterTest` because it failed on my system (ubuntu xenial, jdk 1.8.0_91) with inverse order:\r\n```\r\nFailed tests: \r\n  PropertiesGetterTest.getPropertiesContentThreeElements:48 expected:<key[3=value3\r\nkey2=value2\r\nkey1=value1]> but was:<key[1=value1\r\nkey2=value2\r\nkey3=value3]>\r\n```","created_at":"2016-05-16T14:29:11Z","updated_at":"2016-06-10T16:24:02Z","closed_at":null,"merged_at":null,"merge_commit_sha":"08be36cba32ddfb1c77bc4f5cbf7a9389439de48","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90/commits","review_comments_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90/comments","review_comment_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues/90/comments","statuses_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/statuses/33b741e90856a0afb9dbb712790dc937c71ae37f","head":{"label":"XN137:JENKINS-30467-recursive-variables","ref":"JENKINS-30467-recursive-variables","sha":"33b741e90856a0afb9dbb712790dc937c71ae37f","user":{"login":"XN137","id":1204398,"avatar_url":"https://avatars.githubusercontent.com/u/1204398?v=3","gravatar_id":"","url":"https://api.github.com/users/XN137","html_url":"https://github.com/XN137","followers_url":"https://api.github.com/users/XN137/followers","following_url":"https://api.github.com/users/XN137/following{/other_user}","gists_url":"https://api.github.com/users/XN137/gists{/gist_id}","starred_url":"https://api.github.com/users/XN137/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/XN137/subscriptions","organizations_url":"https://api.github.com/users/XN137/orgs","repos_url":"https://api.github.com/users/XN137/repos","events_url":"https://api.github.com/users/XN137/events{/privacy}","received_events_url":"https://api.github.com/users/XN137/received_events","type":"User","site_admin":false},"repo":{"id":58935059,"name":"envinject-plugin","full_name":"XN137/envinject-plugin","owner":{"login":"XN137","id":1204398,"avatar_url":"https://avatars.githubusercontent.com/u/1204398?v=3","gravatar_id":"","url":"https://api.github.com/users/XN137","html_url":"https://github.com/XN137","followers_url":"https://api.github.com/users/XN137/followers","following_url":"https://api.github.com/users/XN137/following{/other_user}","gists_url":"https://api.github.com/users/XN137/gists{/gist_id}","starred_url":"https://api.github.com/users/XN137/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/XN137/subscriptions","organizations_url":"https://api.github.com/users/XN137/orgs","repos_url":"https://api.github.com/users/XN137/repos","events_url":"https://api.github.com/users/XN137/events{/privacy}","received_events_url":"https://api.github.com/users/XN137/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/XN137/envinject-plugin","description":"","fork":true,"url":"https://api.github.com/repos/XN137/envinject-plugin","forks_url":"https://api.github.com/repos/XN137/envinject-plugin/forks","keys_url":"https://api.github.com/repos/XN137/envinject-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/XN137/envinject-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/XN137/envinject-plugin/teams","hooks_url":"https://api.github.com/repos/XN137/envinject-plugin/hooks","issue_events_url":"https://api.github.com/repos/XN137/envinject-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/XN137/envinject-plugin/events","assignees_url":"https://api.github.com/repos/XN137/envinject-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/XN137/envinject-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/XN137/envinject-plugin/tags","blobs_url":"https://api.github.com/repos/XN137/envinject-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/XN137/envinject-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/XN137/envinject-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/XN137/envinject-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/XN137/envinject-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/XN137/envinject-plugin/languages","stargazers_url":"https://api.github.com/repos/XN137/envinject-plugin/stargazers","contributors_url":"https://api.github.com/repos/XN137/envinject-plugin/contributors","subscribers_url":"https://api.github.com/repos/XN137/envinject-plugin/subscribers","subscription_url":"https://api.github.com/repos/XN137/envinject-plugin/subscription","commits_url":"https://api.github.com/repos/XN137/envinject-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/XN137/envinject-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/XN137/envinject-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/XN137/envinject-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/XN137/envinject-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/XN137/envinject-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/XN137/envinject-plugin/merges","archive_url":"https://api.github.com/repos/XN137/envinject-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/XN137/envinject-plugin/downloads","issues_url":"https://api.github.com/repos/XN137/envinject-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/XN137/envinject-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/XN137/envinject-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/XN137/envinject-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/XN137/envinject-plugin/labels{/name}","releases_url":"https://api.github.com/repos/XN137/envinject-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/XN137/envinject-plugin/deployments","created_at":"2016-05-16T13:36:52Z","updated_at":"2016-05-16T13:36:53Z","pushed_at":"2016-05-16T13:59:38Z","git_url":"git://github.com/XN137/envinject-plugin.git","ssh_url":"git@github.com:XN137/envinject-plugin.git","clone_url":"https://github.com/XN137/envinject-plugin.git","svn_url":"https://github.com/XN137/envinject-plugin","homepage":"","size":686,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jenkinsci:master","ref":"master","sha":"784f1d92af0c4f3a6f5c4c355f0c2e648e59171a","user":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"repo":{"id":2059304,"name":"envinject-plugin","full_name":"jenkinsci/envinject-plugin","owner":{"login":"jenkinsci","id":107424,"avatar_url":"https://avatars.githubusercontent.com/u/107424?v=3","gravatar_id":"","url":"https://api.github.com/users/jenkinsci","html_url":"https://github.com/jenkinsci","followers_url":"https://api.github.com/users/jenkinsci/followers","following_url":"https://api.github.com/users/jenkinsci/following{/other_user}","gists_url":"https://api.github.com/users/jenkinsci/gists{/gist_id}","starred_url":"https://api.github.com/users/jenkinsci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jenkinsci/subscriptions","organizations_url":"https://api.github.com/users/jenkinsci/orgs","repos_url":"https://api.github.com/users/jenkinsci/repos","events_url":"https://api.github.com/users/jenkinsci/events{/privacy}","received_events_url":"https://api.github.com/users/jenkinsci/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jenkinsci/envinject-plugin","description":"","fork":false,"url":"https://api.github.com/repos/jenkinsci/envinject-plugin","forks_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/forks","keys_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/teams","hooks_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/hooks","issue_events_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues/events{/number}","events_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/events","assignees_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/assignees{/user}","branches_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/branches{/branch}","tags_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/tags","blobs_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/statuses/{sha}","languages_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/languages","stargazers_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/stargazers","contributors_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/contributors","subscribers_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/subscribers","subscription_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/subscription","commits_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues/comments{/number}","contents_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/contents/{+path}","compare_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/merges","archive_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/downloads","issues_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues{/number}","pulls_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls{/number}","milestones_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/milestones{/number}","notifications_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/labels{/name}","releases_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/releases{/id}","deployments_url":"https://api.github.com/repos/jenkinsci/envinject-plugin/deployments","created_at":"2011-07-16T20:09:41Z","updated_at":"2016-03-02T09:21:35Z","pushed_at":"2016-05-16T14:29:12Z","git_url":"git://github.com/jenkinsci/envinject-plugin.git","ssh_url":"git@github.com:jenkinsci/envinject-plugin.git","clone_url":"https://github.com/jenkinsci/envinject-plugin.git","svn_url":"https://github.com/jenkinsci/envinject-plugin","homepage":"","size":808,"stargazers_count":35,"watchers_count":35,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":74,"mirror_url":null,"open_issues_count":23,"forks":74,"open_issues":23,"watchers":35,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90"},"html":{"href":"https://github.com/jenkinsci/envinject-plugin/pull/90"},"issue":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues/90"},"comments":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/issues/90/comments"},"review_comments":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90/comments"},"review_comment":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/pulls/90/commits"},"statuses":{"href":"https://api.github.com/repos/jenkinsci/envinject-plugin/statuses/33b741e90856a0afb9dbb712790dc937c71ae37f"}}}}
{"actor":{"display_login":"oleg-nenashev"}}