0

Installed Jenkins by normal user. Set this command into the Execute shell of one job.

echo MY_REPORT=$(echo "http://my_domain/report-$DATE.html")  > var.properties

Got error:

/tmp/jenkins5755572201144086950.sh: line 9: var.properties: Permission denied

If sudo to jenkins user, it can been ran with that command. But how to change normal user to jenkins user when Jenkins running in Execute shell?

zseikyocho
  • 621
  • 2
  • 9
  • 18
  • You can either change the file ownership to your user `chown var.properties YOUR_USERNAME_HERE` (alternatives include adding yourself to a group with write permissions and then assigning that group to the file), or changing the user to the one with write permission to that file. Assuming the "jenkings" user has write permissions, just `sudo -u jenkins` (see [this answer](https://stackoverflow.com/questions/1988249/how-do-i-use-su-to-execute-the-rest-of-the-bash-script-as-that-user)) – afarah Oct 19 '18 at 04:22
  • @afh I tried two ways. Both of them failed. I tried `sudo -u jenkins ...` in the terminal, it works. But not work in `Execute shell` of Jenkisn. The same error. – zseikyocho Oct 19 '18 at 04:44
  • How are the permissions on JENKINS HOME dir looking like ? – ben5556 Oct 19 '18 at 05:04
  • @zseikyocho what are the permissions on the workspace directory of the job? You are creating a new file in that directory, so you need write access on the directory. – Michael Oct 19 '18 at 06:29
  • @Michael I tried `sudo chmod -R a+rw workspace/`, `sudo chmod -R a+rw /var/lib/jenkins/`, `sudo chmod -R g+w workspace`, `sudo chmod -R g+w /var/lib/jenkins/` by the normal user, still not work. – zseikyocho Oct 19 '18 at 06:41
  • @zseikyocho, what is the permission of /tmp directory? Is it 1777? – Manish R Oct 19 '18 at 07:05
  • @ManishR Even I change the `/tmp` folder to 777: `sudo chmod 777 /tmp`, the same failed from its job: `/tmp/jenkins2273902582305684971.sh: line 9: var.properties: Permission denied`. – zseikyocho Oct 19 '18 at 08:51
  • @zseikyocho, The permission of /tmp should be 1777 and not 777 – Manish R Oct 19 '18 at 08:53
  • @ManishR The same. Very strong error. – zseikyocho Oct 19 '18 at 08:57
  • @zseikyocho could you exec this commands in your **Execute shell** box : whoami && ls -la var.properties ?? This could help us to understand your problem. – JRichardsz Oct 19 '18 at 13:49
  • @JRichardsz I have found the reason. This way works: `echo MY_REPORT=$(echo "http://my_domain/report-$DATE.html") > ${WORKSPACE}/var.properties`. Change owner: `sudo chown jenkins:jenkins workspace/[MY_PROJECT]/var.properties`. Check `ls -la /var/lib/jenkins/workspace/[MY_PROJECT]/`, got `-rw-rw-r-- 1 jenkins jenkins 0 Oct 22 10:44 var.properties`. – zseikyocho Oct 22 '18 at 02:18

0 Answers0