JGit Clone Repo kicked off from windows task manager fails - clone

Lets start by saying my code works. I can click a batch file that runs a jar file, that downloads some code from GIT.
Git gitRepo = Git.cloneRepository().setURI( remoteProjectPath )
.setDirectory(new File(destination))
.setCredentialsProvider( new UsernamePasswordCredentialsProvider( repoUser, repoPassword ) )
.setBranch(branch)
.setNoCheckout(true)
.call();
In windows, in my user profile folder i have a .gitconfig file that contains:
[http]
sslverify = false
when I double click the batch file, it works.
But, this is part of an automated process. i need windows task scheduler to execute the batch file at midnight. (time is not important, other than it's when i'm not at work.)
But i can open the task scheduler and click on the task and click 'run' and it fails with the sslverify flag.
"Caused by: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target"
it appears to me that the .gitconfig is only used when I (manually) execute the process. Is there a way to figure out if JGit is attempting to read from a different dir when started by task scheduler?
Or is there another way to make JGit use sslverify=false for a sparse checkout using CloneCommand?
Thanks,

I fought this for so long, and finally find an answer shorting after I post the question.
In a reference to EGit I found: How to change "Location" for "User Settings"
But it worked for me. I went to the system environment variables and created a system variable 'HOME' and set it to a directory containing the .gitconfig file I needed. and now the process works even when kicked off from windows task scheduler.

Related

azure/webapps-deploy#v2 GitHub Action keeps failing with long path error, but I'm using Ubuntu

So I have a workflow that contains the action mentioned in the title. It runs on Ubuntu (runs-on: ubuntu-latest), and I'm getting a long path error:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
Error: Failed to deploy web package to App Service.
Error: Deployment Failed with Error: Package deployment using ZIP Deploy failed. Refer logs for more details.
I don't understand this, because this is a Windows error, but I'm running it on Linux.
Any idea why could this happen? Also, how could I check which path is too long? Is there any option to echo the path that is too long?
Solution:
I locally searched for long paths with a PS script: https://stackoverflow.com/a/41728153/16192320
I found out that all of the long paths are caused by deeply nested node_modules folders, so in the GitHub workflow I ran a command line script to delete those folders. (They weren't needed for deployment.)

wrapper for git, for jenkins pipeline, on windows 10 jenkins slave

What I am trying to accomplish - I want to have a wrapper for git itself, that will retry if the git command fails (timeout/network issue).
I have following dummy code of wrapper:
"C:\Program Files\Git\cmd\git.exe" %*
echo Success!
After changing $PATH and saving the file as git.cmd and removing path to git.exe it works well if I call any git command directly from jenkins:
script {
bat 'git clone %REPO%'
}
result:
(...)
Updating files: 100% (5314/5314), done.
17:58:51 E:\jenkins\workspace\sandbox>echo Success!
17:58:51 Success!
However I want it to work for multibranch pipeline, which uses jenkins git plugin
https://github.com/jenkinsci/git-plugin/blob/master/README.adoc
And running checkout with this plugin results in:
18:48:46 Caused by: java.io.IOException: Cannot run program "git" (in directory "E:\jenkins\workspace\PR-XXXX"): CreateProcess error=2, The system cannot find the file specified
Somehow the git plugin knows, it is missing the git.exe and it is not picking up the git.cmd wrapper script as in the first example. Any suggestions, Guys?
The Git Plugin uses String getGitExe() which returns the git exe for builtOn node, often "Default" or "jgit".
So check first, as in "Relevance of specifying Tool Locations in Jenkins Node Configuration", if you can specify the full path of your git.cmd wrapper in the Git (Default) field of your node (agent) tool configuration.
The Wojtas.Zet confirms in the comments:
I looked the source code of git-plugin and realized there is a way to define custom git executable in the jenkins node GUI
I have clicked it in Jenkins GUI - Jenkins ---> Nodes ---> NodeA (Node properties ---> Tool Locations ---> List of tool locations)

Unable to save output from Rscripts in system directory using Devops Pipeline

I am running Rscripts on a self hosted Devops agent. My Windows agent is able to access the system's directory where its hosted. Below is the directory structure for my code
Agent loc. : F:/agent
Source Code : F:/agent/deployment/projects/project1/sourcecode
DWH _dump : F:/agent/deployment/DWH_dump/2021/
Output loca. : F:/agent/deployment/projects/project1/output_data/2021
The agent is using CMD in the devops pipeline to trigger R from the system and use the libraries from the system directory.
Problem statement: I am unable to save the output from my Rscript in to the Output Loca. directory. It give an error as Probable reason: permission denied error by pointing to that directory.
Output File Format: file_name.rds but same issue happens even for a csv file.
Command leading to failure: saverds(paste0(Output loca.,"/",file_name.rds))
Workaround : However I found a workaround, tried to save the scripts at the Source Code directory and then save the same files at the Output Loca. directory. This works perfectly fine but costs me 2 extra hours of run time because I have to save all intermediatory files and delete them in the end. Keeping the intermediatory files in memory eats up my RAM.
I have not opened that directory anywhere in the machine. Only open application in my explorer is my browser where the pipeline is running. I spent hours to figure out the reason but no success. Even I checked the system Path to see whether I have mentioned that directory over there and its not present.
When I run the same script directly, on the machine using Rstudio, I do not have any issues with saving the file at any directory.
Spent 2 full days already. Any pointers to figure out the root cause can save me few hours of runtime.
Solution was to set the Azure Pipeline Agent services in Windows to run with Admin Credentials. The agent was not configured as an admin during creation and so after enabling it with my userid which has admin access on the VM, the pipelines were able to save files without any troubles.
Feels great, saved few hours of run time!
I was able to achieve this by following this post.

error when pushing changes to git from teamcity (ssh_askpass: exec(/usr/lib/ssh/ssh-askpass))

I am getting
ssh_askpass: exec(/usr/lib/ssh/ssh-askpass): No such file or directory
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights.
This error occurs when trying to push changes to GitHub from TeamCity build.
How can I avoid this error message?
The TeamCity support page includes
I needed to set the environment variable SSH_ASKPASS to point to "C:\Program Files\Git\mingw64\libexec\git-core\git-askpass.exe".
This somehow overrides the unix path with the given correct one
That would assume your TeamCity is running on a Windows server.

Git post-commit hook: How to start a bat-file in Windows

i having a bat-file with name jenkins.bat to start building process on a jenkins server.
Now I want to execute this bat-file as post-commit-hook in git.
Therefore a created following file post-commit in the folder /.git/hooks:
#!/bin/bash
/.git/hooks/jenkins.bat
But eclipse throws me every time an exception when commiting code changes to git! Did I miss something?
You need to use either an absolute or relative path
absolute: /c/...
or, as commented, relative, meaning not starting with a /
./jenkins.bat
Assuming your post-commit hook is executable, and in the <repo>/.git/hooks folder, where your jenkins.bat appears to be.
As Paul mentions in the comments
Doing ./jenkins.bat does not work when the batch file is in the hooks directory: you will get a "no such file" error.
This is because of the hook's working dir.

Resources