Change file ownership with Jenkins

I’ve had Jenkins up and running for a while now on several websites, but there’s one site where I still have to log in every other day to change file ownership. This site has a WordPress blog running under www.somesite.com/blog, while the rest of the site is non-WP.

WordPress needs the directory to be owned by Apache to self-update, install plugins, clear cache, etc. But the site has a custom theme that’s included in the general repo, so Jenkins also needs directory ownership or the build will fail.

Read More

Right now, I’m thinking of having Jenkins change file ownership every deployment, but I don’t know how to go about doing that. Another idea that occurs to me is that we could spin the WordPress theme into its own repo and install it like any other WordPress theme (is that possible? I’ve never used WP before).

Any insight is appreciated!

Related posts

Leave a Reply

1 comment

  1. You can run shell scripts from Jenkins. So you can use chown to change owner of the file or assign it to different group.

    Take a look at Jenkins docs.

    EDIT:

    You are right chown may need to be run under root.
    I believe you have few options:

    • Don’t change owner of the file, just grant access rights to the file from user it’s going to use it (e.g. chmod 770 when we assume that user running Jenkins and user accessing the file are in the same user group). You can create completely separate user group only for this.
    • Use ssh to localhost root account and do chown that way. You can use SSH keys for identity access to root account to avoid entering root credentials (ssh-add)