{"action":"created","issue":{"url":"https://api.github.com/repos/gocd/gocd/issues/1596","labels_url":"https://api.github.com/repos/gocd/gocd/issues/1596/labels{/name}","comments_url":"https://api.github.com/repos/gocd/gocd/issues/1596/comments","events_url":"https://api.github.com/repos/gocd/gocd/issues/1596/events","html_url":"https://github.com/gocd/gocd/issues/1596","id":115079438,"number":1596,"title":"PWD environment variable is not updated to be the same as the pipeline workspace","user":{"login":"scottmuc","id":89754,"avatar_url":"https://avatars.githubusercontent.com/u/89754?v=3","gravatar_id":"","url":"https://api.github.com/users/scottmuc","html_url":"https://github.com/scottmuc","followers_url":"https://api.github.com/users/scottmuc/followers","following_url":"https://api.github.com/users/scottmuc/following{/other_user}","gists_url":"https://api.github.com/users/scottmuc/gists{/gist_id}","starred_url":"https://api.github.com/users/scottmuc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottmuc/subscriptions","organizations_url":"https://api.github.com/users/scottmuc/orgs","repos_url":"https://api.github.com/users/scottmuc/repos","events_url":"https://api.github.com/users/scottmuc/events{/privacy}","received_events_url":"https://api.github.com/users/scottmuc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/gocd/gocd/milestones/9","html_url":"https://github.com/gocd/gocd/milestones/Release:%20Unknown","labels_url":"https://api.github.com/repos/gocd/gocd/milestones/9/labels","id":1482708,"number":9,"title":"Release: Unknown","description":"These issues need interest from someone. They're unlikely to be picked up by the core team, at this point. Not that they're not important. They're just not prioritized for being picked up any time soon.","creator":{"login":"arvindsv","id":172235,"avatar_url":"https://avatars.githubusercontent.com/u/172235?v=3","gravatar_id":"","url":"https://api.github.com/users/arvindsv","html_url":"https://github.com/arvindsv","followers_url":"https://api.github.com/users/arvindsv/followers","following_url":"https://api.github.com/users/arvindsv/following{/other_user}","gists_url":"https://api.github.com/users/arvindsv/gists{/gist_id}","starred_url":"https://api.github.com/users/arvindsv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arvindsv/subscriptions","organizations_url":"https://api.github.com/users/arvindsv/orgs","repos_url":"https://api.github.com/users/arvindsv/repos","events_url":"https://api.github.com/users/arvindsv/events{/privacy}","received_events_url":"https://api.github.com/users/arvindsv/received_events","type":"User","site_admin":false},"open_issues":484,"closed_issues":3,"state":"open","created_at":"2016-01-04T16:20:50Z","updated_at":"2016-01-27T07:01:58Z","due_on":"2020-01-01T05:00:00Z","closed_at":null},"comments":20,"created_at":"2015-11-04T15:33:59Z","updated_at":"2016-01-27T21:18:27Z","closed_at":null,"body":"I'm not even sure if this is a bug, but I was urged to post this here so others can take part in the dialogue.\r\n\r\nI have a Makefile that looks like the following:\r\n\r\n```\r\nmake-pwd:\r\n\t@echo $(PWD)\r\n\r\nshell-pwd:\r\n\t@echo $(shell pwd)\r\n\r\nmake-curdir:\r\n\t@echo $(CURDIR)\r\n\r\nenv:\r\n\t@env\r\n\r\n.PHONY: make-pwd make-curdir shell-pwd env\r\n```\r\n\r\nWhen I have a pipeline that has a task as follows:\r\n\r\n```\r\n          <exec command=\"make\">\r\n            <arg>make-pwd</arg>\r\n            <arg>shell-pwd</arg>\r\n            <arg>make-curdir</arg>\r\n            <arg>env</arg>\r\n            <runif status=\"passed\" />\r\n          </exec>\r\n```\r\n\r\nThe results look like:\r\n\r\n```\r\n14:12:31.951 /data/go-agent/workspace\r\n14:12:31.953 /data/go-agent/workspace/pipelines/make-pwd-test\r\n14:12:31.953 /data/go-agent/workspace/pipelines/make-pwd-test\r\n14:12:31.954 GO_SERVER_URL=https://<redacted>:8154/go/\r\n14:12:31.954 SHELL=/bin/sh\r\n14:12:31.954 _=/usr/lib/jvm/jdk1.8.0_25/bin/java\r\n14:12:31.954 XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt\r\n14:12:31.954 GO_FROM_REVISION_GIT=195438d2ee17be1bc730ea15101740870459782b\r\n14:12:31.954 GO_STAGE_NAME=test\r\n14:12:31.954 PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games\r\n14:12:31.954 LOG_FILE=/data/go-agent/workspace/go-agent-bootstrapper.log\r\n14:12:31.954 AGENT_STARTUP_ARGS=-Dcruise.console.publish.interval=10 -Xms128m -Xmx256m   \r\n14:12:31.954 GO_TO_REVISION_GIT=195438d2ee17be1bc730ea15101740870459782b\r\n14:12:31.954 PWD=/data/go-agent/workspace\r\n14:12:31.955 GO_SERVER_PORT=8153\r\n14:12:31.955 HOME=/srv/go-agent\r\n14:12:31.955 LOGNAME=ci\r\n14:12:31.955 GO_PIPELINE_COUNTER=1\r\n14:12:31.955 SHLVL=1\r\n14:12:31.955 AGENT_WORK_DIR=/data/go-agent/workspace\r\n14:12:31.955 USER=ci\r\n14:12:31.955 GO_PIPELINE_LABEL=1-195438d\r\n14:12:31.955 OLDPWD=/srv/go-agent\r\n14:12:31.955 MAKEFLAGS=\r\n14:12:31.955 MFLAGS=\r\n14:12:31.955 MAIL=/var/mail/ci\r\n14:12:31.955 GO_PIPELINE_NAME=make-pwd-test\r\n14:12:31.955 GO_SERVER=ci.dev.s-cloud.net\r\n14:12:31.955 GO_TRIGGER_USER=changes\r\n14:12:31.956 GO_REVISION_GIT=195438d2ee17be1bc730ea15101740870459782b\r\n14:12:31.956 NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat\r\n14:12:31.956 GO_JOB_NAME=make\r\n14:12:31.956 GO_STAGE_COUNTER=1\r\n14:12:31.956 LOG_DIR=/data/go-agent/workspace\r\n14:12:31.956 MAKELEVEL=1\r\n```\r\n\r\nWith a task that looks like:\r\n\r\n```\r\n          <exec command=\"/bin/bash\">\r\n            <arg>-c</arg>\r\n            <arg>make make-pwd shell-pwd make-curdir env</arg>\r\n            <runif status=\"passed\" />\r\n          </exec>\r\n```\r\n\r\nThe output is:\r\n\r\n```\r\n14:34:56.127 /data/go-agent/workspace/pipelines/make-pwd-test\r\n14:34:56.128 /data/go-agent/workspace/pipelines/make-pwd-test\r\n14:34:56.128 /data/go-agent/workspace/pipelines/make-pwd-test\r\n14:34:56.129 GO_SERVER_URL=https://<redacted>:8154/go/\r\n14:34:56.129 SHELL=/bin/sh\r\n14:34:56.129 _=/usr/bin/make\r\n14:34:56.129 XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt\r\n14:34:56.129 GO_FROM_REVISION_GIT=89cdddb6306393c6e8f0374ec0193c42a973499d\r\n14:34:56.129 GO_STAGE_NAME=test\r\n14:34:56.129 PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games\r\n14:34:56.129 LOG_FILE=/data/go-agent/workspace/go-agent-bootstrapper.log\r\n14:34:56.129 AGENT_STARTUP_ARGS=-Dcruise.console.publish.interval=10 -Xms128m -Xmx256m   \r\n14:34:56.129 GO_TO_REVISION_GIT=89cdddb6306393c6e8f0374ec0193c42a973499d\r\n14:34:56.129 PWD=/data/go-agent/workspace/pipelines/make-pwd-test\r\n14:34:56.129 GO_SERVER_PORT=8153\r\n14:34:56.130 HOME=/srv/go-agent\r\n14:34:56.130 LOGNAME=ci\r\n14:34:56.130 GO_PIPELINE_COUNTER=3\r\n14:34:56.130 SHLVL=2\r\n14:34:56.130 AGENT_WORK_DIR=/data/go-agent/workspace\r\n14:34:56.130 USER=ci\r\n14:34:56.130 GO_PIPELINE_LABEL=3-89cdddb\r\n14:34:56.130 MAKEFLAGS=\r\n14:34:56.130 MFLAGS=\r\n14:34:56.130 MAIL=/var/mail/ci\r\n14:34:56.130 GO_PIPELINE_NAME=make-pwd-test\r\n14:34:56.130 GO_SERVER=ci.dev.s-cloud.net\r\n14:34:56.130 GO_TRIGGER_USER=changes\r\n14:34:56.130 GO_REVISION_GIT=89cdddb6306393c6e8f0374ec0193c42a973499d\r\n14:34:56.130 NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat\r\n14:34:56.130 GO_JOB_NAME=make\r\n14:34:56.131 GO_STAGE_COUNTER=1\r\n14:34:56.131 LOG_DIR=/data/go-agent/workspace\r\n14:34:56.131 MAKELEVEL=1\r\n```\r\n\r\nThe key difference is in the value of the `PWD` environment variable and the echoing of it when invoking `make`.\r\n\r\nThere was some [gitter](https://gitter.im/gocd/gocd?at=563a12bfc74a90c744793551) conversation about this. From what I can understand, the \"fork exec\" implementation of the task runner leaves the `PWD` env variable unchanged from the agents working directory.\r\n\r\nMy [\"research\"](https://www.google.de/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=PWD+vs+CURDIR+Make) on `make` standards shows that `PWD` might not be a reliable variable since it depends on the shell setting the variable correctly. That being said, that seems to be a pretty common expectation. Would that be a breaking and/or a difficult change for the `go-agent` to manage?"},"comment":{"url":"https://api.github.com/repos/gocd/gocd/issues/comments/175858503","html_url":"https://github.com/gocd/gocd/issues/1596#issuecomment-175858503","issue_url":"https://api.github.com/repos/gocd/gocd/issues/1596","id":175858503,"user":{"login":"grahamc","id":76716,"avatar_url":"https://avatars.githubusercontent.com/u/76716?v=3","gravatar_id":"","url":"https://api.github.com/users/grahamc","html_url":"https://github.com/grahamc","followers_url":"https://api.github.com/users/grahamc/followers","following_url":"https://api.github.com/users/grahamc/following{/other_user}","gists_url":"https://api.github.com/users/grahamc/gists{/gist_id}","starred_url":"https://api.github.com/users/grahamc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grahamc/subscriptions","organizations_url":"https://api.github.com/users/grahamc/orgs","repos_url":"https://api.github.com/users/grahamc/repos","events_url":"https://api.github.com/users/grahamc/events{/privacy}","received_events_url":"https://api.github.com/users/grahamc/received_events","type":"User","site_admin":false},"created_at":"2016-01-27T21:18:27Z","updated_at":"2016-01-27T21:18:27Z","body":"I'm satisfied. If a user currently puts `sleep 10 | less` into their exec command, shellwords will escape it enough so the executable to actually get run will be called `sleep 10 | less`. (Yeah, it is possible.)\r\n\r\nI am a bit concerned about making the command outputted in a way the user will recognize it, but this is A-OK with me. I really appreciate all the conversation we've had around this here.\r\n\r\nAlso, there was some chatter on Gitter about it starting here: https://gitter.im/gocd/gocd?at=56a92b5380ad69394a7ad69c"}}