Drone CI SSH CANNOT execute commands in Windows - windows

I'm having an issue with a Drone CI pipeline step. I'm trying to run some commands on a remote Windows server using the appleboy/drone-ssh image, but I'm encountering an issue where some commands are not executing.
Here's an example step that's failing:
- name: '部署到Web' image: appleboy/drone-ssh settings: host: 192.168.50.249 port: 22 username: administrator password: from_secret: pws_web script: - echo "Web Master" - ls
When I run this step, the echo command works correctly and outputs "Web Master" to the console, but the ls command does not seem to have any effect.
I've tried different commands, such as dir, but they all exhibit the same behavior. I know that the SSH connection is working because I'm able to run echo without any issues.
Can someone please point me in the right direction on how to troubleshoot this issue? I'm not sure if this is an issue with the SSH connection or with the command that I'm running.
Thank you in advance for any help you can provide.
Best regards,
i try many command
all not working
cd d:\hotac
cmd /c git checkout master
cmd /c git pull --tags origin master
powershell.exe -Command "& { Set-Location 'd:\hotac'; git checkout master; git pull --tags origin master}"

Related

Execute a command (TortoiseHG) through cmd remotely (PsExec)

Basically I want to use PsExec in order to navigate to a specificar folder in a remote computer and performe "hg update branch". I've tried to create the following batch but I'm not able to perform the command:
psexec cmd.exe /c "cd C:\Project\hg update Test"
It's reading as the "hg update Test" was a folder instead of command to be done... I'm tilting over here and this seems like a basic thing :(. How do I pass the "hg update branch" as cmd command through PsExec?
You don't need to change directory, just tell HG what path to operate in:
psexec cmd.exe /c "hg update -R C:\Project\ Test"
The help says:
-R --repository REPO repository root directory ...

Cleaning up file based variables. ERROR: Job failed: exit code 1

I am using gitlab-ci to automate build and release. In the last job, I want to upload the artifacts to a remote server using lftp.
$(pwd)/publish/ address is the artifacts that were generated in the previous job. And all variables declared in the gitlab Settings --> CI / CD.
This the job yaml code:
upload-job:
stage: upload
image: mwienk/docker-lftp:latest
tags:
- dotnet
only:
- master
script:
- lftp -e "open $HOST; user $FTP_USERNAME $FTP_PASSWORD; mirror -X .* -X .*/ --reverse --verbose --delete $(pwd)/publish/ wwwroot/; bye"
Note that lftp transfers my files, however, I'm not sure all of my files are transferred.
I added echo "All files Transfered." but it never runs.
There is no error and warning in the pipeline log but I got the following error:
I don't know what is it for. Have anyone faced the error and have found any solution?
Finally, I solved the problem by some changes in lft command parameters.
The point in troubleshooting ERROR: Job failed: exit code 1 is that to use commands with the verbose parameter that return sufficient log to enable you to troubleshoot the problem. Another important point is to know how to debug shell scripts such as bash, powershell, or etc.
Also, you can run and test commands directly in a shell, it is helpful.
The following links are helpful to troubleshoot command-line scripts:
How to debug a bash script?
5 Simple Steps On How To Debug a Bash Shell Script
Use the PowerShell Debugger to Troubleshoot Scripts
For lftp logging:
How to enable lftp protocol logging?

It' s possible to works SSH and git command in gitlab-ci?

In my gitlab-ci.yml, I have an SSH connection to another server, all my command are working except the git commands
They block the script with the message:
WARNING: terminal is not fully functional
- (press RETURN)
and my script is blocked
My code in gitlab-ci :
allow_failure: false
script:
- ssh -tt root#1IP 'cd PATH; git branch;docker run -it -v $PWD:PATH -w /PATH cypress/included:6.5.0 | tee result.txt'
Without the git command, it's work.
Of course, in my remote server, git branch work's fine.
Any ideas ?
Thanks :) :)
That is an error message coming from less, used as a pager by Git, as I documented here.
Try:
git config --global core.pager "less -d"; git branch; ... (rest of the commands)
The -d option (from less man page) option suppresses the error message normally displayed if the terminal is dumb;

Why can I not use the command history in minikube ssh

I have a minikube K8s 1 node cluster on my Windows 10 pc. I can SSH into this cluster using minikube ssh.
The problem that I am experiencing is that I can't use the arrow keys to bring back the previous command. I did some looking around and diagnostics:
set -o | grep history gave history on
echo $HISTFILE gave /home/docker/.bash_history. This is indeed in the home folder of the user and the file was present after exiting and executing minikube ssh again
echo $HISTSIZE and echo $HISTFILESIZE both gave 500
echo $SHELL gave /bin/bash
All these things tell me that command history should be enabled, but it doesn't seem to be the case.
I tried using both Powershell and cmd to run minikube ssh, both with and without Windows Terminal.
Both PowerShell and cmd themselves have a working command history, but once SSHing using minikube, the history in the bash shell doesn't work.
Does anyone know how to get the command history to work after executing minikube shh?
Edit:
I have tried minikube ssh --native-ssh=false, but this didn't change anything.
It seems to be a problem with the SSH client you are using. You can try with the --native-ssh=false option:
minikube ssh --native-ssh=false
You can also try with different alternatives or with something like the ssh version that comes with Cygwin.
There is already an unsolved issue related to this. (Feel free to update)
✌️

Git Portable 64 Bash not working in Windows Server 2016 Task Scheduler

I need help trying to figure out why Git repository commands are not not executing when run in a script in Windows Server 2016 Task scheduler. All works OK when I execute them in a command console.
In the Windows Server 2016 Task Scheduler, my Action "Start a Program" is: C:\Apps\repo.scripts\UpdateMyRepo.bat
The UpdateMyRepo.bat cmd code is:
SET HOME=C:\Users\Repo
REM change to MyRepo git working repository
C:
cd \MyRepo
REM execute my script bash script to update my repository
C:\Apps\Git\bin\bash.exe --login -i -c "/c/Apps/repo.scripts/UpdateMyRepo.sh"
The UpdateMyRepo.sh bash code is
#!/c/Apps/Git/bin/bash.exe -x
export HOME=/c/Users/Repo
cd /c/MyRepo
# write a log entry so we know we are in the repository folder
ls -al > /c/Apps/repo.scripts/myrepofolder.log
# write the git --version to a log file so we know git is working
/c/Apps/Git/bin/git.exe --version > /c/Apps/repo.scripts/version.log
# write the git status to a log file so we know git repository commands work
/c/Apps/Git/bin/git.exe status > /c/Apps/repo.scripts/status.log
# write a done log entry and quit the bash shell
echo done > /c/Apps/repo.scripts/done.log
exit
Everything works in Windows 2016 Task Scheduler except the git status command. The git status writes an empty blank status.log file. Actually, it seems like any other commands, like git add, git commit, git push, etc., that act on the repository yield blank output.
If I execute the command manually when logged in as the Repo user and double clicking on the C:\Apps\repo.scripts\UpdateMyRepo.bat in Windows file explorer or running in a console, all works perfectly and the repository git status is written to the status.log. I get the "null" results when executing the task from the Task Scheduler either manually or on trigger.
Please help me figure out how to run git repository commands in Windows Server 2016 task scheduler. I have already tried too many variations of commands, scripts, and permissions to list each that did not work here.
Platform Details:
Windows Server 2016 Standard, all current updates
Git Portable 64bit, 2.17.1.windows.2
Repository files are stored on in the operating system and task scheduler's local hard drive, not in a network share
update: When I run the Git repository tasks in the WS2016 Task Scheduler and figured out how to log some of the output, I get the following error:
fatal: this operation must be run in a work tree
The repository folder is NOT a "bare" repository. So I am suspecting that the WS2016 Task Scheduler is applying additional permission constraints that do not apply to the user account assigned in the task. I get this same error if I try to run the tasks in an Admin Console instead of a normal user console.
First, most of Git commands writes their output to stderr, not stdout
So you need to redirect stderr to stdout, using for instance &> instead of >.
Second, to be sure all your Git command will be executed in the right working tree/repo, you can add environment variables for the repository location
export GIT_WORK_TREE=/c/path/to/my/repo
export GIT_DIR=/c/path/to/my/repo/.git

Resources