git pull throws exception as "e = {"could not rmdir 'xxx': The process cannot access the file because it is being used by another process."} - libgit2sharp

My code is from wiki page:
https://github.com/libgit2/libgit2sharp/wiki/git-pull
I am quite sure I have no other processes(file exploer\cmd etc) opened the directory. When I use git pull in cmd, it gets success.
and my local repo status is as below
get the local repo synchronized with its remote upstream as what we get by 'git pull'

Related

Windows container volume performance issues

I'm trying to set up jenkins to run some pipelines for me. As part of my pipeline, I want to checkout a second git repository, which I am placing into a subdirectory of the workspace.
However, this pipeline step will fail on a clean workspace, with an error like:
! [new branch] develop -> origin/develop (unable to update local ref)
error: cannot lock ref 'refs/remotes/origin/master': unable to resolve reference 'refs/remotes/origin/master': Not a directory
From what I can tell, this is happening because git is failing to create the .git/refs/remotes/origin/master file (however it does manage to create the .git/refs/remotes/origin/ directory, which isn't created by the git init command).
Upon playing around, I can reproduce this issue in the docker container by creating a new empty directory and running
git init
git fetch --tags --force --progress -- {giturl} +refs/heads/*:refs/remotes/origin/*
which appears to be what the jenkins step is doing.
If I run the git fetch a second time, it will then succeed.
So far, this is all within a mounted volume in the container. If I try to recreate the problem not in a mounted container, I can't. The
git init
git fetch --tags --force --progress -- {giturl} +refs/heads/*:refs/remotes/origin/*
steps work as expected, meaning that something appears to be going wrong within the mounted volume for some reason.
Does anyone know what might causing these issues within the mounted volume?
Incidentally I also have a stage doing:
bat "\"C:/Program Files/LLVM/bin/clang-format.exe\" -n --style=file --fallback-style=none .\\Source\\*.c .\\Source\\*.cpp .\\Source\\*.h .\\Source\\*.hpp 2>&1 | python ./libraries/clang-to-junit.py ${WORKSPACE} Clang-Format > clang-format-results.xml"
bat "type clang-format-results.xml"
junit allowEmptyResults: true, skipOldReports: true, skipPublishingChecks: true, testResults: 'clang-format-results.xml'
which creates a clang-format-results.xml file to report results of clang format. However the junit step fails to find the file if it's newly created, despite the type command outputting the file just fine. Seems like this could be related also to filesystem issues...

Git SSH checkout fails with Jenkins and GitLab

When I attempt a build on my Jenkins job that is configured to checkout from GitLab I am getting below error output (truncated) :
....................
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from git#10.777.77.777:root/xxx.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
....................................................
....................................................
at hudson.model.Executor.run(Executor.java:431)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- git#10.777.77.777:root/xxx.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: Load key "/var/lib/jenkins/workspace/gitlabjenkinsdemo#tmp/jenkins-gitclient-ssh1964800292912998995.key": invalid format
Permission denied, please try again.
Permission denied, please try again.
git#10.170.8.204: Permission denied (publickey,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2102)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:624)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
I am trying to setup a CI/CD pipeline as per this post Jenkins_Gitlab
I expected that the private key I added should enable checkout out of the box (Note : Both Jenkins server and Gitlab server are running on the same Debian instance).
In the ~/.ssh directory I have the following :
root#myservername:~/.ssh# ls -ld
drwx------ 2 root root 4096 Oct 18 15:30 .
In the source code management tab of my Jenkins job I have also added the SSH link that I extracted from my project in Gitlab. However what I am unsure of is the message below that the project is showing in Gitlab :
What am I missing ?
Both Jenkins server and Gitlab server are running on the same Debian instance
Ideally, they would run with their own associated service account, not "root".
But still, even as root, this should work.
Check which private SSH key you have added, and make sure, at least for testing, it wasn't one protected with a passphrase (meaning the private key file does not have a Proc-Type: 4,ENCRYPTED line in it)
That might be a cause for the jenkins-gitclient-ssh1964800292912998995.key": invalid format you have.
(That or you have copied the private key file content with CRLF instead of LF as end-of-line)
(or you have copied a public key, where a private one was expected, or vice-versa)
From the discussion:
the private key had to be registered again in Jenkins (making sure its eol -- end-of-line -- are LF, not CRLF)
the branch needs to be renamed:
My repo had master when I did git init, so had to rename branch to main when I set the GitLab remote

one folder not uploaded in bitbucket

I am having some problems with bitbucket. All my project folders and files are uploaded except the src folder. The src folder in my computer has files and folders. But it is not appearing in bitbucket. Why is the src folder appearing like that in bitbucket?
I enter the commands:
git init
git add .
git commit -m "initial commit of full repository"
git remote add origin
https://boidurja#bitbucket.org/boidurja/kapstone.git
and I get this error:
F:\BOP consultancy and services\vuetify project\kapstoneui>git remote add
origin
https://boidurja#bitbucket.org/boidurja/kapstone.git
fatal: remote origin already exists.
And I enter this command:
git push -u origin --all
and I get this error:
F:\BOP consultancy and services\vuetify project\kapstoneui>git push -u
origin --all
To https://bitbucket.org/boidurja2/kapstone.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to
'https://boidurja2#bitbucket.org/boidurja2/kapstone.git'
hint: Updates were rejected because the remote contains work that you do not have locally. This is usually caused by another repository pushing to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Can anyone help?

How to checkout a Bitbucket Git-LFS repo in Jenkins?

I have a Git LFS setup on our Bitbucket server, and can clone it on my Mac since I'm the owner.
Now I'm trying to set this up so a Jenkins job can clone the repo, and so on the SCM section I have
Repository URL: git#server.company.com:user/path/repo.git
Credentials: uernamePwCreds
It can get to the repo fine, but when it tries to checkout a Git-LFS file, it gets the following access error. See the Permission denied (publickey) error on last line.
FATAL: Could not checkout 104e35fb26dc1d3ed1689523cccb6e97829c0feb
hudson.plugins.git.GitException: Command "git checkout -f 104e35fb26dc1d3ed1689523cccb6e97829c0feb" returned status code 128:
stdout:
stderr: Downloading MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (144 KB)
Error downloading object: MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (716be41): Smudge error: Error downloading MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (716be4107b362e413dc1ae29dc88e9b79e680def2c725ecc2d73268c4ea66e75): batch request: Permission denied (publickey).: exit status 255
How do I setup the "Git-LFS-specific" level authentication?
I don't want to use a Jenkinsfile for now.
Try adding "Additional Behaviours" -> "Git LFS pull after checkout" in the Git section of the SCM configuration for your job.

Setting git private repository project on jenkins server

I am trying to set git private repo on jenkins server. I have installed git plugin and also github. when I set repo url in jenkins project ui the error is
Failed to connect to repository : Command "git -c core.askpass=true
ls-remote -h git#github.com:repo/project.git HEAD" returned
status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedl
What I have done up to now:
My server user and jenkin user( both are in same server) are different. Though it seems to me these are not related. jenkins user are given all credintial.
In my server under var/lib/jenkins/.ssh(.ssh is created by me) I added ssh key . Public key is added to github repo.
By swithcting user to jenkins i can clone the project by this ssh. So i think there is not any public key adding problem.
I have googled the problem. there are many solutions. I tried most of them. But still no solution. Probably I am missing something.
My repo url is something like this
git#github.com:repo/project.git
If your HOME set in /var/lib/jenkins/ then i hope all the step you have been done successfully :)
Then one thing may be happen for your case. Like when you switch the user by using:
su jenkins
This command means that you switch the user but the home directory will be same as a root's home!
So you need to switch user by confirming the specific user home also switched. TO doing so, you need to follow:
su -s /bin/bash jenkins
Then you need to generate either the ssh public key once again or just update the known host. This will work.
Related Link
It depends on what HOME is set to when Jenkins is running: git will look for the ssh (public and private) keys under $HOME/.ssh.
Simply add a build step with an echo $HOME, and make sure your .ssh is in that folder.

Resources