Gitlab Executor TTY - gitlab

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.

Related

The subtle difference in an ansible script "SHELL" and the directly running Shell commands on an ubuntu machine 20.04 EC2?

I come with a Vagrant script that pulls down an bionic 18 which then runs an ansible playbook which generates two EC2s ubuntu 20.04 which successfully run though every "task:" I assign. I am able to run everything I want in a largely automated download and execution for a publisher subscriber method. Here is the issue: I can run my .sh and .py scripts manually and the systems works, but when I use the ansible methods I must be doing something wrong much like these solutions point to:
Shell command works on direct hosts but fail on Ansible
ansible run command on remote host in background
https://superuser.com/questions/870871/run-a-remote-script-application-in-detached-mode-in-ansible
What I want to do is simply correct the issue with this, and run it in the background.
- name: Start Zookeeper
shell: sudo /usr/local/kafka-server/bin/zookeeper-server-start.sh /usr/local/kafka-server/config/zookeeper.properties </dev/null >/dev/null 2>&1 &
- name: Sleep for 30 seconds and continue with play
wait_for:
timeout: 15
- name: Start Kafka broker
shell: sudo /usr/local/kafka-server/bin/kafka-server-start.sh /home/ubuntu/usr/local/kafka-server/config/server.properties </dev/null >/dev/null 2>&1 &
I have tried it with just a single "&" at the end as well as passing in explicit calls to my user account "ubuntu". I've used the "become: yes". I really don't want to use a daemon especially since others seem to have used this successfully before.
I do want to note that a glaring sign to you that I can't seem to think through is that it hangs when I don't include the &, but if I do include the & it just outright fails, which made me think it was running, but the script won't proceed because these are listener processes.
# - name: Start Zookeeper
# become: yes
# script: /usr/local/kafka-server/bin/zookeeper-server-start.sh
# args:
# chdir: /usr/local/kafka-server/config/zookeeper.properties
This failed, and I'd rather not create another script to copy over the directories and localize it if there is a simple solution to the first block of code.
Multiple ways to skin this cat, but I'd rather just have my mistake on the shell ansible command fixed, and I don't see it.
As explained in the answers written in your third link:
https://superuser.com/questions/870871/run-a-remote-script-application-in-detached-mode-in-ansible
This happens because the script process is a child process from the shell spawned by ansible. To keep the process running after ansible has finished you would need to disown this child process.
The proper way to do this is configuring the software (zookeeper in your case) as a service. There are plenty of examples for this such as:
https://askubuntu.com/questions/979498/how-to-start-a-zookeeper-daemon-after-booting-under-specific-user-in-ubuntu-serv
Once you have configured it as a service, you can start it or stop it using ansible service module.

Run script in userdata Detached

I am trying to start and run a long running process on my ec2 instance via userdata.
This process needs to stay running for the lifespan of the instance.
This process also needs to run as another user i.e centos and not root.
I am able to run the script and it works fine but it will not allow me to ssh into the server until I stop/start the instance.
Here is how I am running the process now.
I get the error Connection refused
/bin/su -c "/home/centos/downloadAndStart.sh" - centos /dev/null &/dev/null &
without running the script I am able to ssh into the server as soon as it initializes.
I believe this is because of something like the process is still attached to the PID of the userdata script? Does that make sense?
I am not entirely sure why I cannot ssh into the instance until after I restart the instance.

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 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.

Unable to run remote script on ubuntu using jenkins

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.

Resources