Jenkins Permission Denied on shell execute - jenkins

I'm trying to do a shell execute in Jenkins build step. I have a binary executable in /home/ubuntu/.local/bin/aws which is called from Jenkins executable script.
In the build output log, it reads /tmp/jenkins2312.sh: line 2: /home/ubuntu/.local/bin/aws: Permission denied
Adding Jenkins user to Root Group didn't help.

Give execute permission to aws file.
chmod +x /home/ubuntu/.local/bin/aws

Is the file executable for jenkins?
If you are on the machine you could set it to have suitable executable permissions (chmod 755 /home/ubuntu/.local/bin/aws )
You should only have to do this once.

In Ubuntu you need to stop and start Jenkins after you change jenkins's user's permissions. For me, restarting Jenkins didn't work but stop and start did.

your aws executable should in this location
/usr/local/bin/aws
then should work as you want, I don't think on .local

Related

Jenkins - Disappears all jobs after restart

The jenkins version is :
<version>2.186</version>
<installStateName>RESTART</installStateName>
<numExecutors>2</numExecutors>
<mode>NORMAL</mode>
All jobs disapperad after restart jenkins : sudo service jenkins restart
/var/lib/jenkins/config.xml includes them. The config file has no conflict. I have checked it using an xml validator.
How can I fix it? There is no job in jenkins dashboard.
Either option will work
1)
choose option reload configurations from disk (Manage Jenkins/Reload Configuration from Disk).
Or
2) Can you try to install Stable Jenkins and import all jobs n folder structure to new jenkins folder structure.
Hope that might help if by mistakenly someting is courupted or deleted in current folder structure of jenkins.
I had same issue I solved it using above method
I would first check folder permissions:
stat /var/lib/jenkins/jobs
stat /var/lib/jenkins
Then I would change permissions if needed:
chown -R your_user /var/lib/jenkins
You will need to restart Jenkins and maybe reboot the machine.

Cannot Build build.xml file in wso2 esb home/bin directory

In WSO2 Documentation, they have said Open a command prompt (or a shell in Linux) and go to the <ESB_HOME>\bin directory. Then run the ant command as shown below to build the build.xml file.
In My Case If I run ant Command it shows command not found even though I run cmd in bin of wso2.
So Can anyone help me with this?
you need to install 'ant' first when you are using Windows.
https://ant.apache.org/manual/install.html

Jenkins add permission for composer

I have few projects in Jenkins, but I have problem with build this projects.
Everytime Jenkins throw exception :
rename(/var/lib/jenkins/.composer/cache/composer-temp.phar,/usr/local/bin/composer):
Permission denied
When I add permission chmod -R 777 /usr/local/bin/composer, then work but for one project. When I try build next project, Jenkins throw this exception.
Jenkins is in sudoers.
What do I need to Jenkins had the permission?

Executing custom shell script to build in jenkins

I have setup a jenkins job to build my project. I have a jake.sh file in my project and the code is pulled from github. I want "npm install" command to be executed and then jake.sh to be executed once the the code is checked out.
How can I configure this in jenkins? I have tried givin ./jake.sh and jake.sh in Build->Execute Shell section
According what you tell I think the problem can be
The script is not marked as a executable. In this case add in Build -> Execute Shell (in case you have linux) sudo chmod 777 path_to_script/jake.sh.
The script is not in the base directory. Remembeber that when you execute a bash script, the current directory is /path_to_job/workspace. So you have first to move to the script folder (cd path_to_script) or specify the path when running it: ./path_to_script/jake.sh.
I hope this solves your problem.
A workaround for shell scripts can be to run the script as
bash ./jake.sh
instead of
./jake.sh
Then you don't have to do chmod. Useful when you wipe the workspace before every build.
In the same manner, if you have a nodejs shell script or python script, you can run node myscript.js / python myscript.py.

Jenkins how to rename war file

I have deployed a war file in a remote machine using Jenkins. Now I want to rename the war file through jenkins before it extracts the work folder? How can this be done? I tried post deployment action -> execute shell and mv file.war to new-file.war but it returns an error saying : mv: cannot stat `file.war': No such file or directory.
Suppose there was something wrong with my path it would not even have gone to remote location. but for me, after scp' ing it to remote location thru jenkins, and when i try to do a mv, it fails.. What could the reason be??
Adding additional Step of Execute shell during Add build Step or Add post-build action stage, normal renaming shell command mv can be used to rename artifacts.
Note: Make sure use the correct path(Relative to project/workspace root)
Your mv command is probably executed in another directory than the one you are expecting.
To know the directory your script is running in without reading the jenkins / plugin documentation add
echo "pwd of script is: " `pwd`
to your shell script and inspect the output of the jenkins build - that way you can be sure about the directory the script is run in.

Resources