Unable to run remote script on ubuntu using jenkins - linux

I am trying to ssh to my deployment server to run a script using jenkins build server but it is giving error:
Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/test/workspace
[workspace] $ /bin/sh -xe /tmp/hudson2847284723784326.sh
+ ssh user#serverIP
Pseudo-terminal will not be allocated because stdin is not a terminal.
Host key verification failed.
Build step 'Execute shell' marked build as failure
Finished: FAILURE
I am using Execute shell build utility in jenkins. Steps used are:
ssh user#serverIP
cd pathofscript
./script.sh
I can login manually in server without using password. I used this article to setup password less login : http://www.linuxproblem.org/art_9.html
Kindly let me know what am I doing wrong.

Try to use Jenkins ssh plugin.

Related

Gitlab Executor TTY

I'm trying to leverage Gitlab Runner to execute builds on remote machine. I have the runner and am using the shell executor to kick off builds locally. Unfortunately, I'm receiving the following error when I kick off something:
Using Shell executor...
standard in must be a tty
ERROR: Job failed: exit status 1
I suspect this is occurring because the user that I'm passing in with the --user parameter can access tty. Any thoughts on how to get this working? The shell type is bash.
Check first if GitLab is doing a sudo once connected to the remote machine, to change user.
If that is the case, with visudo (on that remote machine), do:
Defaults:[username] !requiretty
If not, as in here, check if this is a JVM initialization issue.

running SSH script command from jenkins using SSH

To deploy application on linux ubuntu server I have bunch of SSH commands that i currently run using PuTTY. The server has local account serviceaccount1. In PuTTY i connect to server using serviceaccount1 and executes the following commands one by one
cd /home/serviceaccount1/cr-ml
script /dev/null
screen -S data_and_status
cd cr-ml/notebooks
source activate crml
unset XDG_RUNTIME_DIR
jupyter kernelgateway --api='kernel_gateway.notebook_http' --seed_uri='data_and_status_api.ipynb' --port 8894 --ip 0.0.0.0
...
...
and so on
Now i want automate this using Jenkins. I installed SSH plugin, configured credential using SSH Username serviceaccount1 with private key
Then created a new jenkins project and added a build step Execute shell scripts on remote host using ssh and then add all the above commands.
When i build the jenkins project, it get stuck at executing 2nd command script /dev/null
i see the following console output
To me, it seems the culprit is the screen -S data_and_status command. Once you start a screen, I don't think you would be able to execute the subsequent commands over the SSH connection.
Alternatively, you can try using a tool like Ansible to run a bunch of commands against a remote server.

Jenkins CI - SSL CA error

NOTE: This is .NET Core on Linux (Ubuntu)
I am setting up some CI infrastructure for .NET Core code and am running into a strange issue. Specifically, when it comes to package restore (dotnet restore).
The Jenkins instance that I am running is hosted on Azure via a Bitnami Jenkins image. In my build, I have a number of build steps. One of them (the one that actually triggers dotnet restore) is an Execute Shell.
When I run whoami from it, I get that I am the user tomcat. When dotnet restore is triggered from within the build step, however, I get the following error:
06:22:37 log : Retrying 'FindPackagesByIdAsync' for source 'https://api.nuget.org/v3-flatcontainer/system.runtime.serialization.primitives/index.json'.
06:22:37 log : An error occurred while sending the request.
06:22:37 log : Problem with the SSL CA cert (path? access rights?)
That same issue does not happen if I SSH into the box and do a sudo su - tomcat - running dotnet restore on the same folder from a SSH session works, while doesn't work in the Execute Shell step (despite the fact that both run in the same user context).
What am I missing that might be causing this?

Jenkins execute shell standard terminal required error

I have Jenkins master-slave setup and had a job that is going to execute on slave machine.
Inside job configuration I have some Linux commands like:
shutdown the tomcat
start the tomcat
that are being executed in the Jenkins execute shell and require sudo permission.
When I switch the user using
su -
for running all the commands as root user It is giving me the error standard in must be a tty
Even I tried running the command with sudo but it failed.
Note : I have Jenkins Master-slave setup on AWS EC2 so I had few restrictions like :
I can not set password for root user
Can not give full access to the tomcat directory
Adding user to the sudoers
Kindly help me out.

Executing node.js script remotely

I am setting continuous integration using Jenkins server for my Node.js application. For deployment I am using a powershell script and for that I have installed powershell plug-in. The script will need to perform the following tasks in the order.
# Step1
# Stop all the currently running services on web server. For that I am trying to
# execute maintenance.js remotely from the build server under node
node \\SharedWebServerFolder\Utilities\maintenance.js stopServices
# Step2
# Copies all the resources to server at \\SharedServerWebFolder
# Step3
# Start the services
node \\SharedWebServerFolder\Utilities\maintenance.js startServices
I have no problem executing Step2. My question is about Step1 and Step3.
Should I execute maintenance.js remotely from the build server? Is this even possible? ( Assume I have installed node.js on the build server)
Should I have one more PowerShell script on the web server which executes maintenance.js locally? So basically deployment script (from build server) will execute remote PowerShell script (which is on web server) and that remote PowerShell script will execute maintenance.js locally. In this scenario I don't have to install Node.js on the build server.
What is recommended?
People generally use ssh to execute commands remotely. I think you want to execute a command from your build server on your production / staging server.
see linux execute command remotely
this is simple where the remote box is a linux box.
If your remote is a Windows box then you can still run an ssh server on it but its more painful to setup. you might try Bitvise SSH Client.
Once your ssh client is setup correctly you should be able to execute remote commands from your build server.
I have used Jenkins SSH Plugin for deployment in my remote staging/production servers.I would recommend to execute your 'maintenance.js' in web server machine instead of your build server.You can just trigger 'maintenance.js' execution in staging/production servers from build server using ssh.I believe the execution of 'maintenance.js' remotely from the build server is hard to achieve.

Resources