Jenkins Create Scheduled Builds - Failed

@rahul456 @Ayman @kodekloud3 @Inderpreet

Jenkins Create Scheduled Builds Failed even after the successfull job completion on validation. Please find the screenshots attached, could you please guide me what went wrong on the task.
3

I have user review in first attempt failure and it went failed again.

hi @jgeorg0001, as per your script, seems like you have missed sudo password for natasha user on storage server.

@rahul456

I have already created passwordless login between app server and storage.
Even the sudo failed the files are copied to the target directory, verified by logging into the storage server. The screenshot already attached. Can you please make the task pending for me.

@jgeorg0001 As per the console output, there is an error [sudo] password for tony: These repeated three times mean the password not accepted.

You can try a different approach. Since you have established password less authentication you also can set the folder permission so that you don’t have to run with sudo privilege.

@mihsan I have already retried after review as you suggested- passwordless auth between app server and storage server-. The project has been successfully built without the sudo error and the verified the scheduled build. Still the task failed with same error. It would be better we have some direction in task that the plugin names which we need to use.

@jgeorg0001 Agree but if the team specify the plugin then it will also limit the alternatives for approaching the task. However what i have seen is, the KKE team specify the options they are perticular in validation.
If you are sure the Jenkins job is running regularly as per the schedule and the log files are copied without any issue at the end of each build (you can verify this with the file timestamp), then report it here and tag KKE team.
They will have a look as well.

@rahul456 @kodekloud3 @Ayman

I have go the task again and successfully completed job but task got failed again as per screenshots.
can someone guide me where it went wong. i have spend almost 5 hours learn and complete task.


Here is the screenshot of scheduled builds

All the timestamps are correct the job runs. Please verify

@rahul456, @Tej-Singh-Rana @kodekloud3 @Ayman

Can some one guide me on this. Waiting for your comments.

hi @jgeorg0001, this task is already pending on your dashboard.

Please try to record the solution, and share the video if the issue occurs again.

1 Like

@Inderpreet , @Ayman , @KodeKloud2, @kodekloud-support3

Can you please assist?, I completed the task however it is marked as failed

Can you please let me know what’s wrong with my approach?

Did your build run successfully? Because I see 2 problems:

  • You used sudo -S but you have not supplied the sudo password (i.e. Ir0nM@n) to the command via stdin
  • You are trying to scp file from stapp01 to /usr/src/security on ststor01. Sudo user natasha will not have permissions to this directory by default. So this step will fail. To get around this, one approach is to copy the file to /tmp directory on ststor01 and then move the files to the actual location

Hi @rahul456.

The steps I used to create job:

echo “Ir0nM@n” | sudo -S mkdir -p /tmp/logs1

echo “Ir0nM@n” | sudo -S cp /var/log/httpd/access log /tmp/logs1

echo “Ir0nM@n” | sudo -S cp /var/log/httpd/error log /tmp/logs1

echo “Ir0nM@n” | sudo -S chmod 777 /tmp/logs1

echo “Ir0nM@n” | sudo -S chown -R root:root /tmp/logs1

echo “Ir0nM@n” | sudo -S yum install sshpass -y

sshpass -p “Bl@kW” scp -o ‘StrictHostKeyChecking=no’ /tmp/logs1/access log natasha@ststor01:/usr/src/devops

sshpass -p “Bl@kW” scp -o ‘StrictHostKeyChecking=no’ /tmp/logs1/error log natasha@ststor01:/usr/src/devops

And configured it to Build Periodically : */2 * * * *

And as u see the last 2 builds are running 2 mins and in the video at the end we see 2 logs copied to storage server (review video : KodeKloud Engineer | Real Project Tasks on Real Systems)

@rahul456 Can you review once. I don’t have video recording now.

hi @selvag, as per your steps, it seems like you haven’t install package sshpass on Storage Server.

@rahul456,
Now i have enable passwored less between app03 and storage server and create job for move logs. but still jobs say no logs moved.

Logs are created correctly.

sudo scp -o StrictHostKeyChecking=no -r /etc/httpd/logs/ natasha@ststor01:/tmp

sudo scp -o StrictHostKeyChecking=no -r /var/log/httpd/ natasha@ststor01:/tmp

sudo mv /tmp/logs/access_log /usr/src/finance

sudo mv /tmp/logs/error_log /usr/src/finance

Job logs as below :

Started by user Admin User

Running as SYSTEM

Building in workspace /var/jenkins_home/workspace/copy-logs

[SSH] commands:

sudo scp -o StrictHostKeyChecking=no -r /etc/httpd/logs/ natasha@ststor01:/tmp

sudo scp -o StrictHostKeyChecking=no -r /var/log/httpd/ natasha@ststor01:/tmp

[SSH] executing…

[SSH] completed

[SSH] exit-status: 0

[SSH] commands:

sudo mv /tmp/logs/access_log /usr/src/finance

sudo mv /tmp/logs/error_log /usr/src/finance

[SSH] executing…

[SSH] completed

[SSH] exit-status: 0

Finished: SUCCESS

hi @selvag, can you please share (DM) exact commands ?

I did point out the problem in your review. I’m not sure why you have 2 copy instructions in your build job: first one copying all files from from /etc/httpd/logs and then next one copying all files from /var/log/httpd. As there are duplicate copies, if there are access_log and error_log in /var/log/httpd, they will overwrite the files copied from /etc/httpd/logs. Hence your task could fail.

it working , but you can optimize it by the following:

echo Am3ric@ | sudo -S cp /var/log/httpd/access_log ~/

echo Am3ric@ | sudo -S cp /var/log/httpd/error_log ~/

echo Am3ric@ | sudo -S yum install sshpass -y

sshpass -p “Bl@kW” scp -o ‘StrictHostKeyChecking=no’ ~/access_log natasha@ststor01:/usr/src/devops
sshpass -p “Bl@kW” scp -o ‘StrictHostKeyChecking=no’ ~/error_log natasha@ststor01:/usr/src/devops