Release script fails with "/bin/sh: 1: ./release-tasks.sh: Permission denied" - heroku

I followed article
https://devcenter.heroku.com/articles/release-phase#specifying-release-phase-tasks
to configure to run a script during release step.
unfortunately the release results in the following error (Release Log):
/bin/sh: 1: ./release-tasks.sh: Permission denied
how can I fix this?
my Procfile:
release: ./release-tasks.sh
web: gunicorn ph.wsgi --preload --log-file -
release-tasks.sh (simplified):
#!/bin/bash
python manage.py migrate --noinput

Git ignores most file permissions, but it does track the executable bit. Make your script executable and check it in, e.g.
chmod +x release-tasks.sh
git add release-tasks.sh
git commit -m "Make release-tasks.sh executable"
Then deploy as normal.
On Windows, you won't have chmod. Use the --chmod option to git add instead:
git add --chmod=+x release-tasks.sh
git commit -m "Make release-tasks.sh executable"

Related

Execute a shell script in release phase on Heroku

I have two commands to execute in release phase and as per this tutorial (https://devcenter.heroku.com/articles/release-phase), I have included them in a shell script named release.sh (located in the root of my Django project).
#!/bin/bash
python manage.py migrate
python manage.py compress
In my Procfile, I added the script thus, as described in the article.
release: ./release.sh
web: gunicorn myapp.wsgi --log-file -
But during release I get the following error.
/bin/sh: 1: ./release.sh: not found
Then the release fails.
I don't know if the problem is with the path in Procfile (I also tried bash $PWD/releash.sh) or the file not being available at the time it is called. Any help would be appreciated.
EDIT:
My release.sh was in a subfolder and that's why it wasn't found, but now I'm getting permission denied.
/bin/sh: 1: ./release.sh: Permission denied
This worked
chmod u+x release.sh && ./release.sh
So Procfile becomes
release: chmod u+x release.sh && ./release.sh
web: gunicorn myapp.wsgi --log-file -
For this to work, release.sh must be executable
Locally, you could run chmod a+x release.sh. But you would not want to do that on heroku, so instead you can change the Profile to have this:
release: bash release.sh
web: gunicorn myapp.wsgi --log-file -

Why does my git bash always start at master branch?

I have a Windows PC with git installed. Whenever I start git bash, it always stand at /c/Users/_user with master branch as below:
NativeKiwi#nkiwi MINGW64 ~ (master)
I think it should look like this:
NativeKiwi#nkiwi MINGW64 ~
I had a look at people around, found out that they don't have (master) at their first start using git bash. I checked git repo at where I stand with git remote -v but there is nothing.
The string shown in your prompt depends on your PS1 environment variable.
Please check your .bash_profile or .bashrc for the configuration of PS1 environment variable.
I had the same issue (due to running git init) in the wrong directory and fixed it by running rm -rf .git in that directory.
You are seeing master because you created a git repository at the current path using the git init command. Always create git repositories in the folders containing project files. Consider running rm -rf .git command.

How do I trigger a "behave" test from a Jenkins Execute Shell build step?

I have a series of BDD selenium tests that run using a selenium standalone server. To run them, I enter the following code in the terminal (once I'm in the right directory):
source project/bin/activate # Opens a virtualenv with appropriate interpreters
behave
and when the tests are done:
deactivate # Ends the virtualenv
I have configured a Jenkins project that accesses a GitHub repo with the same files and tests. In the project there is a build step that executes a shell command. The code there is:
#!/bin/bash
cd dev #Enter right directory
source project/bin/activate #Activate virtualenv
behave
see Execute Shell Build step
However, when I build the project I get the following output:
Started by <user>
Building in workspace /Users/Shared/Jenkins/Home/workspace/Tutorial
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url git#github.com:<url>.git # timeout=10
Fetching upstream changes from git#github.com:<url>.git
> git --version # timeout=10
> git fetch --tags --progress git#github.com:<url>.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision b62c3e873be4fba3daa1b29a9954a130c768a8f4 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f b62c3e873be4fba3daa1b29a9954a130c768a8f4
> git rev-list b62c3e873be4fba3daa1b29a9954a130c768a8f4 # timeout=10
[Tutorial] $ /bin/bash /Users/Shared/Jenkins/tmp/hudson719949293776127111.sh
/Users/Shared/Jenkins/tmp/hudson719949293776127111.sh: line 4: behave: command not found
Build step 'Execute shell' marked build as failure
Finished: FAILURE
see Console Output
I've tried variations and seem to always get a similar results. How do I get these tests run?
Edit:
I've also tried creating a shell script (run.sh) that runs behave with the following code:
#!/bin/sh
exec project/bin/behave
and then running the script in the Jenkins build step with the code ./run.sh instead of behave or the variations I mentioned in the comments, but I get the same errors.
I finally figure it out. I created a virtualenv using the Shining Panda plugin and needed to activate it in the build step. In order to not create a new virtualenv every time I build the project, I created a new job that just created a new virtualenv. The configuration build step in that job looks like this:
Then, in the job I had previously created, the Execute Shell step looks like this:
Where
/Users/Shared/Jenkins/Home/shiningpanda/jobs/ae39534a/virtualenvs/d41d8cd9/bin/activate
is the direct path to the virtualenv created. I then have no problem getting behave to run.

System level git config in mac

I am able to see global and local config files at usual locations.
But if i type
git config --system --list
it gives me
fatal: unable to read config file '/Library/Developer/CommandLineTools/usr/etc/gitconfig': No such file or directory
Any idea why it is looking there?
And why it is not set? Where is
system git config location for Mac?
There is no file at /etc/gitconfig or $HOME/.config/git (prescribed location got *nix and osx respectively)
EDIT
doing
sudo git config --system --list
does not help
#Abhijit Mazumder:
I know this is an old question, but I had a similar issue when attempting to set a system level git config value on my mac and thought I would post my solution here in case it could help you.
NOTE: I strongly suspect that if you simply create the
'/Library/Developer/CommandLineTools/usr/etc/' directory and create a
file called gitconfig within that directory, then your attempts at
viewing or setting system level git config values will be successful.
My first attempt at setting a system level git config value on my mac was:
git config --system alias.cl clone
This resulted in an error:
error: could not lock config file /Applications/Xcode.app/Contents/Developer/usr/etc/gitconfig: No such file or directory
I thought perhaps I needed to add 'sudo' to the command:
sudo git config --system alias.cl clone
But running the command with 'sudo' gave me the same error:
error: could not lock config file /Applications/Xcode.app/Contents/Developer/usr/etc/gitconfig: No such file or directory
So, from the root directory on my mac, I switched into the 'usr' directory mentioned in the error, just to see what was in there:
cd Applications/Xcode.app/Contents/Developer/usr/
I was surprised to find that there was no 'etc' directory. The only directories I saw were 'bin', 'lib', 'libexec', and 'share'.
So I decided to create what was missing. I first created an 'etc' directory:
sudo mkdir etc
And then created a gitconfig file in the 'etc' directory:
sudo touch etc/gitconfig
I was then able to set a system level git config value with the following command:
sudo git config --system alias.cl clone
In order to confirm that the system level git config value had actually been set, I viewed the contents of the gitconfig file.
I first used the unix 'cat' command while inside my 'usr' directory:
cat etc/gitconfig
The output from the 'cat' command was:
[alias]
cl = clone
Then I used a git command (the same one you were trying to use in your question) to check that my system level git config value had been set:
git config --system --list
The output from this command was:
alias.cl=clone
The last thing I needed to do to ensure that I had placed my file in the proper location was try the alias I had created, so I tried running:
git cl
Running this command using the alias I created resulted in the following output, which confirmed for me that everything was working properly:
You must specify a repository to clone.
usage: git clone [<options>] [--] <repo> [<dir>]
-v, --verbose be more verbose
-q, --quiet be more quiet
--progress force progress reporting
-n, --no-checkout don't create a checkout
--bare create a bare repository
--mirror create a mirror repository (implies bare)
-l, --local to clone from a local repository
--no-hardlinks don't use local hardlinks, always copy
-s, --shared setup as shared repository
--recursive initialize submodules in the clone
--recurse-submodules initialize submodules in the clone
--template <template-directory>
directory from which templates will be used
--reference <repo> reference repository
--dissociate use --reference only while cloning
-o, --origin <name> use <name> instead of 'origin' to track upstream
-b, --branch <branch>
checkout <branch> instead of the remote's HEAD
-u, --upload-pack <path>
path to git-upload-pack on the remote
--depth <depth> create a shallow clone of that depth
--single-branch clone only one branch, HEAD or --branch
--separate-git-dir <gitdir>
separate git dir from working tree
-c, --config <key=value>
set config inside the new repository
I have not come across this error as my machines are only used by me so setting --global level is enough, however that location looks reasonable (I assume you are using the git supplied with the Xcode command line tools).
Using sudo to configure what you want should work:
$ sudo git config --system <name> <value>

Setup a git bare repo on a windows apache server

I need help in setting up a bare git repo on an apache web server. I followed the below instructions
$ cd /var/www/htdocs/
$ git clone --bare /path/to/git_project gitproject.git
$ cd gitproject.git
$ mv hooks/post-update.sample hooks/post-update
$ chmod a+x hooks/post-update
I got these instructions from here
http://git-scm.com/book/en/Git-on-the-Server-The-Protocols.
I try to run
git clone "http://ip-addr/gitproject.git"
, but am not successful and neither the push command works. Do you have any suggestions on what to do next.
At least try it without the double-quotes:
git clone http://ip-addr/gitproject.git
And if it still hangs, check the log of your Apache server, to see if it is contacted at all.

Resources