I am using Jenkins to 'execute shell' command
ls -l /mnt/ftpbackup/ftpuser/*
But getting error
ls: cannot open directory /mnt/ftpbackup/ftpuser/: Permission denied
I am able to run the very same command when I log as 'jenkins' user, see below:
-bash-4.1$ id
uid=493(jenkins) gid=490(jenkins) groups=490(jenkins),504(ftpuser) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
-bash-4.1$ ls -l /mnt/ftpbackup/ftpuser
total 48116044
....
are you trying to execute this command in the jenkins master through jenkins?
try whoami command to find out which user jenkins is using to execute commands
if you are executing in any node, the jenkins will connect to that node using the credentials you have provided in node settings, please check that.
Related
I use Jenkins for CICD. After cloning the repository, I want to copy some file from cloned repository to a remote server using sshpass (scp).
sh """sshpass -p '$KEY'-o StrictHostKeyChecking=no scp *.json $UNAME#$PROD_IP:/home/test"""
But I get error in output:
sshpass: Failed to run command: No such file or directory
What's wrong I'm doing ?
After a long search I found the answer. So, you need to switch to the jenkins user and create a pair of keys on his behalf and add to the remote server to which you need to access. Then add the private key into Jenkins credential and use.
So I was trying to deploy a simple CD pipeline using docker by ssh’ing into my AWS Linux EC2 instance in the WSL2 terminal. The job is failing every time returning the following error:
Started by user Navdeep Singh Running as SYSTEM Building on the
built-in node in workspace /var/lib/jenkins/workspace/todo-dev
[todo-dev] $ /bin/sh -xe /tmp/jenkins6737039323529850559.sh + cd
/home/ubuntu/project/django-todo /tmp/jenkins6737039323529850559.sh:
2: cd: can’t cd to /home/ubuntu/project/django-todo Build step
‘Execute shell’ marked build as failure Finished: FAILURE
DockerFile contents:
FROM python:3 RUN pip install django==3.2
COPY . .
RUN python manage.py migrate
CMD [“python”,“manage.py”,“runserver”,“0.0.0.0:8000”]
Everything goes fine. This error cd: can’t cd to /home/ubuntu/project/django-todo Build step ‘Execute shell’ marked build as failure Finished: FAILURE is not an actual.
Your agent Node is not online.
To fix the problem, find commands on your jenkins web page after an agent setup. You need to run those commands from your terminal. See the screenshot for more details.
Make sure that your jenkins public IP and node agent public IP are the same. If an error occurs, you need to run some commands on the terminal. This is not a real error.
this issue follow this step which i give you
For Agent--->
change your ip here(44.203.138.174:8080) to your EC2 ip
1.curl -sO http://44.203.138.174:8080/jnlpJars/agent.jar
2.java -jar agent.jar -jnlpUrl http://44.203.138.174:8080/manage/computer/todo%2Dagent/jenkins-agent.jnlp -secret beb62de0f81bfd06e4cd81d1b896d85d38f82b87b21ef8baef3389e651c9f72c -workDir "/home/ubuntu"
For JOb --->
sudo vi /etc/sudoers
then add this command below root access in sudoers file
jenkins ALL=(ALL) NOPASSWD: ALL
3.then goto the ubuntu directory using cd .. then run this codes
grep ^ubuntu /etc/group
id jenkins
sudo adduser jenkins ubuntu
grep ^ubuntu /etc/group
4.restart the jenkins relogin
sudo systemctl stop jenkins
then you good to go
I'm trying to run a powershell command to create a resource in Azure under Jenkins.
Powershell code :
az login --service-principal -u -p --tenant
Select-AzSubscription -SubscriptionId
New-AzResourceGroup -Name exampleGroup -Location westus
But when this ps command is run in Jenkins while creating a new job it throws below error :
Error
I've added Azure service principal in Jenkins under Global configuration so that it can call the parameters and run the script. How can this be fixed ?
I'm trying to build and then run a docker image on Jenkins. I have set up Jenkins on ubuntu on an AWS ec2 server. When I try to build I get this error:
For reference, I have also attached my JenkinsFile.
pipeline {
agent any
stages {
stage('Start') {
steps {
echo 'Starting to build the docker-react-app.'
}
}
stage('building docker image') {
steps {
sh 'sudo docker build -t docker-react-app .'
}
}
stage('runing docker image') {
steps {
sh 'sudo docker run -dp 3001:3000 docker-react-app'
}
}
}
}
I am using Jenkins with the default administrator account.
I have also added the Jenkins user to the docker group. But it is hasn't solved the issue. I have also verified that by running:
cat /etc/group | grep docker
Which outputs:
docker:x:998:ubuntu,jenkins
Let me know if you need any further information.
The error says that your current user can’t access the docker engine, because you’re lacking permissions to access the unix socket to communicate with the engine.
In order to solve this issue :
Run below command in any of your shell:
sudo usermod -a -G docker $USER
NOTE : do a complete restart of machine and also jenkins.
After this step : Completely log out of your account and log back in.
For more info : https://docs.docker.com/engine/install/linux-postinstall/
Try to run your pipeline scripts via jenkins user on your target server
Maybe you should add jenkins user to root group
hello everyone i have a problem which is , i can't run an ansible playbook from aws instance (ansible system) to another aws (docker system) instance
it shows me this error
fatal: [x.x.x.x]: FAILED! => {"msg": "Missing sudo password"}
can any one help me please , i will be grateful
From: Missing sudo password in Ansible
You should give ansible-playbook the flag to prompt for privilege escalation password.
ansible-playbook --ask-become-pass
add the user into visudo file on the host server some thing like this
{username} ALL=(ALL) NOPASSWD: ALL
Actually i didn't get your scenario very well,do you want to connect to docker container from your playbook?
if that is the case you can add ssh public key 'id_rsa.pub' (generate this file by the command ssh-keygen inside the instance from where you want to connect to docker) to authorized_keys file inside docker container. When shh keys are there you don't need a sudo password.
You can do this in either in Dockerfile or using ssh-copy-id
if you are not using ssh, and having this error while running task with 'become: true' or 'become: sudo', then add the following line to /etc/sudoers list
<username> ALL=NOPASSWD: ALL