vsts build Agent Shell provide password - shell

I'm currently creating a build agent for our DevOps.
With the agent I want to stop solr via shell script on the unix server. The problem is, I need to insert a password, to stop the service.
Is there a simple way to provide the password in the shell script? The current script:
service solr stop
throws the following error:
2020-03-12T12:50:27.0480993Z Successfully connected.
2020-03-12T12:50:27.0483958Z service solr stop
2020-03-12T12:50:29.7903365Z
2020-03-12T12:50:29.8193011Z ##[error]Failed to stop solr.service: Interactive authentication required.
2020-03-12T12:50:29.8208401Z
2020-03-12T12:50:29.8208979Z
2020-03-12T12:50:29.8209589Z ##[error]See system logs and 'systemctl status solr.service' for details.
2020-03-12T12:50:29.8209971Z
2020-03-12T12:50:29.8210587Z ##[error]Command failed with errors on remote machine.
2020-03-12T12:50:29.8341862Z ##[section]Finishing: stop solr
I also tried to provide the password on the script, like:
echo <password> | sudo -S service solr stop
It works on the server locally, but the buildserver throws:
2020-03-12T12:52:17.9543478Z Successfully connected.
2020-03-12T12:52:17.9545108Z echo *** | sudo -S service solr stop
2020-03-12T12:52:18.9946984Z ##[error][sudo] password for ***:
2020-03-12T12:52:23.4808034Z ##[error]Command failed with errors on remote machine.
2020-03-12T12:52:23.5019910Z ##[section]Finishing: stop solr
Any other ideas how I could remotely stop solr with a shell script?

As mentioned I found a solution and posted it in another post. Here's the answer link: https://stackoverflow.com/a/60666738/5835745

Related

Connect to Jenkins server via SSH

I was wondering if I can ssh a local instance of Jenkins. When I go to Jenkins CLI menu in the UI, there's a comment saying the below:
You can access various features in Jenkins through a command-line
tool. See the documentation for more details of this feature. To get
started, download jenkins-cli.jar, and run it as follows:
java -jar jenkins-cli.jar -s http://localhost:8080/ -webSocket help
So I tried it and it worked but it only gave a list of limited commands which I can execute. So I searched more and found I can use -ssh instead of -webSocket but I get the same result as -webSocket.
What I want to do is accessing the Jenkins bash so I can test my build scripts.
I'm trying
ssh 127.0.0.1 -p 23 // I set this port in the settings
but I keep getting :
shell request failed on channel 0
is it impossible what I'm trying to do? if not, how can I achieve it?

SSH timeout error on Azure DevOps CD pipeline

I am getting an timeout error when trying to deploy to an VM instance hosted on AWS. Manually I can log ing using
ssh -i myKeyFile.pem myuser#IP
Once I accessed the remote machine I can execute some docker commands and everything works fine. But now that I need to automated that on the CD pipeline is where I am getting the following error:
2020-06-02T21:37:12.6877276Z Trying to establish an SSH connection to ***#IP:port
2020-06-02T21:38:52.4629461Z ##[error]Failed to connect to remote machine. Verify the SSH service connection details. Error: Error: Timed out while waiting for handshake.
2020-06-02T21:38:52.4685976Z ##[section]Finishing: Run shell commands on remote machine
The steps I follow to make the SSH connection are:
I created a SSH service connection on the project settings in Azure DevOps
I created the CD pipeline
I added a SSH task with the following parameters
When I manually trigger it to test if it works, the release start working fine but after 1:43 minutes more or less is when I got the error:
Then, when I review the logs, it is the same error I pasted at the beginning:
[error]Failed to connect to remote machine. Verify the SSH service connection details. Error: Error: Timed out while waiting for handshake
I've increase the handshake timeout settings from the default one (20000) to 90000, but no luck.
Any one has face this problem before?
Seems there is an ongoing error with the default agent pools from Azure DevOps. Lot of people have been reported this and Azure DevOps teams is working on it at the time this post is been written (I couldn't find the post where all that is details. I will add this later on).
The workaround is
To create a self-hosted agent.
After this has been created you will need to re-create your CD pipeline using the new self-hosted agent.
The rest of the SSH task configuration depends on your needs. But if you want to test the SSH connection works, just print something:
echo 'I'm connected'
After this you CD pipeline should be working fine.
More details on how to created the Self-Hosted Agent on Windows. There are also links for Linux and Mac.
I had a similar issue with a VM in Azure. It turned out I had set the security group to only allow SSH in from my local network and Azure Dev-Ops agents obviously run in a Microsoft network and were coming from a different IP Address range. The solution was to open up SSH to all source IP Addresses. You can get the list of IP address ranges Dev-Ops agents use but they appear to change every week which isn't very helpful.
See https://learn.microsoft.com/en-us/azure/devops/organizations/security/allow-list-ip-url?view=azure-devops#microsoft-hosted-agents

Starting Bitbucket Server in Ansible

I'm using Vagrant and Ansible to create my Bitbucket Server on Ubuntu 15.10. I have the server setup complete and working but I have to manually run the start-webapp.sh script to start the server each time I reprovision the server.
I have the following task in my Bitbucket role in Ansible and when I increase the verbosity I can see that I get a positive response from the server saying it will be running at http://localhost/ but when I go to the URL the server isn't on. If I then SSH in to the server and run the script myself, getting the exact same response after running the script I can see the startup webpage.
- name: Start the Bitbucket Server
become: yes
shell: /bitbucket-server/atlassian-bitbucket-4.7.1/bin/start-webapp.sh
Any advice would be great on how to fix this.
Thanks,
Sam
Probably better to change that to an init script and use the service module to start it. For example, see this role for installing bitbucket...
Otherwise, you're subject to HUP and other issues from running processes under an ephemeral session.

Unable to run powershell script remotely leading to test agent deployment failures in Azure

I am having a setup where I need to run automation script from a test agent. But the build step fails
with the following message
connecting to remote server DevBox02 failed with the following error message
: The client cannot connect to the destination specified in the request. Verify that the
service on the destination is running and is accepting requests. Consult the logs and
documentation for the WS-Management service running on the destination, most commonly IIS or
WinRM. If the destination is the WinRM service, run the following command on the
destination to analyze and configure the WinRM service: "winrm quickconfig". For more
information, see the about_Remote_Troubleshooting Help topic.'. For troubleshooting
But when I analysed the test agent machine, I am getting the messsage that WinRM service is already running
PS C:\Windows\system32> winrm quickconfig
WinRM service is already running on this machine.
WinRM is already set up for remote management on this computer.
PS C:\Windows\system32>
Not sure why I am getting this message when I am able to see WinRM Service is up and running
I have also configured the firewall exception .
Please help me in pointing what I am missing. Thanks a lot
WinRM/Remote Powershell service isn't configured correctly, try to reconfigure the service by following the steps here: How to Run PowerShell Commands on Remote Computers.

How do I solve the Authentication failure by Mesos

I have get the script file from https://github.com/nmilford/rpm-mesos/blob/master/mesos-master and I start to execute
service mesos-master start
end up I got this
Starting Mesos Master daemon (mesos-master):
Password:
su: Authentication failure
How do I start my mesos-master?
This is not a Mesos authentication failure. It is a failure to run su $mesosUser, when $mesosUser may not even be set. This repo is very old, so I would recommend looking for a newer rpm. If you don't need to build it yourself, you can download one from http://mesosphere.com/downloads/details/index.html#apache-mesos

Resources