Jenkins/Github: Apparently .git/config doesn't exist? - github

So after installing the Github plugin to Jenkins CI and attempting to add a job for my Github project to compile automatically after a Github push to master, Jenkins reports that .git/config doesn't exist.
I went to /var/lib/jenkins and created .git and the config file and chowned them to jenkins:nogroup.
The error persisted. I then went and did this in my own VPS home directory. Error persists.
I then made a home folder for the jenkins user with no shell and did the same steps. Error persists.
Which .git/config is it referring to?!
Edit:
The actual error I'm referring to is:
Failed to connect to repository : Command "git config --local credential.helper store --file=\"/tmp/git7406572387997126825.credentials\"" returned status code 255:
stdout:
stderr: error: could not lock config file .git/config: No such file or directory

Solved...switched to SSH.
Steps:
Assume control of Jenkins user. su jenkins
(You may need to set a password for it first (make it good!) sudo passwd jenkins.
Go home: cd ~.
Generate key: ssh keygen -t rsa -C "email". (No passcode)
Copy $JENKINS_HOME/.ssh/id_rsa.pub to Github.
Set Jenkins credentials to authenticate to Github using the private key.
Works fine.

Found a neat workaround here: https://groups.google.com/forum/#!topic/git-users/pyv6ldFxUio
mkdir ~/.git
git config --global user.email "m...#school.com"
https://groups.google.com/forum/#!topic/git-users/pyv6ldFxUio

Related

fatal: unsafe repository is owned by someone else - GitHub actions workflow

I have two yml files configured in the GitHub actions. When new code is pushed to master, one yml file deploys the files to specific website folder, and the other one to another website folder.
Even though both websites are on the same server, one of the deploy.yml files is not executing jobs and it's throwing this error.
fatal: unsafe repository ('/var/www/yayyy.net/public_html' is owned by someone else)
To add an exception for this directory, call:
git config --global --add safe.directory /var/www/yyyy.net/public_html
Error: Process completed with exit code 128.
at this step:
- name: Add temp repo access
run: |
cd $DEV_WEBSITE_PATH
git remote set-url origin https://anything:${{ secrets.GITHUB_TOKEN }}#github.com/yyyyy/website.git
I tried adding extra step before that step and added this safe.directory command but then it's showing permission denied error.
error: could not lock config file /var/www/.gitconfig: Permission denied
Adding sudo before the command then throws this error:
sudo: sorry, you must have a tty to run sudo
I'm confused what I'm missing, can you help?
The.gitconfig did not exist and the username didn't have permission to create it. So, I created it manually and changed ownership to the username.

git push to github in a batch job sumitted to a server using qsub

I set a ssh-agent and gave it an id_rsa key, so I don't have problem using git command on a terminal of a linux server to update to github, but when I try to do this by a bash script using qsub to submit the job to the server, I got the following error messages,
On branch master
nothing to commit, working directory clean
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
my shell script is,
#!/bin/bash
git add *.png
git commit -m "upload_fig"
git push
I also set ~/.ssh/config like the following,
Host remoteHost
ForwardAgent yes
Host github
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Anyone knows how to solve this issue?
Thanks!
In addition: I have set id_rsa key to github and I can use git command on the local terminal.
What you are looking for might be in what you are looking for might be in this. I'm guessing you didn't add your public key, ~/.ssh/id_rsa, to your github account.

Cannot use git to clone in remote web server

I have created a Github repo to where I push my local changes using Git Bash, without any problems. I can also use Git Bash to connect to my remote web server (shared hosting) and navigate to the folder where I want to clone my Laravel site.
This is where the problems begin. When I do
$ git clone git#github.com:myusername/mylaravelsite.git
I get the error message:
Permission denied (publickey)
After some searching for a solution I found that I should make sure that I have a key by doing this:
$ eval "$(ssh-agent -s)"
Which gave this answer:
Agent pid 122372
Then according to the instructions I should do this
$ ssh-add -l
Which gave me this message:
The agent has no identities
Reading up a bit more I try to add the key again by doing
$ssh-keygen -t rsa
...which generated a key pair that I added with ssh-add, I was prompted for a passphrase which I entered twice.
Now, I still get Permission denied (publickey) when I try to access my github repo with ssh. I should also mention that I have created a new SSH key at the github account where I pasted the key I created (I opened .ssh/id_rsa-pub with notepad and copied the content).
What more can I try?
Finally found the answer in case anyone else has the same problem. It turns out that the public key also must exist in the remote web server (in the .ssh folder I uploaded the same rsa_id and rsa_id.pub files, that I created locally), not only locally and in the Github account.
Once I had figured that out and uploaded those files to the webserver, it worked to clone my github repo :-).

How to get Jenkins checking out private vendor repo via composer

I've got a project that I wan to build with Jenkins.
The project is hosted in a private GitHub repo and I've put the SSH public key in GitHub of my user "deploy".
The project gets checked out fine thanks to the deploy credential in Jenkins git plugin section in the build config.
But a vendor lib which is hosted as private in same GitHub organisation is loaded via a build step command :
php composer.phar install -o --prefer-dist --no-dev
I've installed Jenkins git plugin in order to checkout the main repo from GitHub via private SSH key.
But when the composer tries to checkout the sub project I get
Failed to clone the git#github.com:Organisation/Repo.git repository, try running in interactive mode so that you can enter your GitHub credentials
I've tried to get the composer command ran as a different user without success with stuff like :
su - deploy -c 'php composer.phar install -o --prefer-dist --no-dev'
looks weird anyway. I'd like to figure out the proper way of having the composer doing his job. Thought ?
Jenkins is actually running the shell commands as "jenkins" user.
It means that "jenkins" needs access to GitHub.
Then all the git#github.com:Organisation/Repo.git will work without additional credentials.
Here is explained how to grant Jenkins access to GitHub over SSH
# Login as the jenkins user and specify shell explicity,
# since the default shell is /bin/false for most
# jenkins installations.
sudo su jenkins -s /bin/bash
ssh-keygen -t rsa -C "your_email#example.com"
# Copy ~/.ssh/id_rsa.pub into your Github
# Allow adding the SSH host key to your known_hosts
ssh -T git#github.com
# Exit from su
exit
Inspired from: Managing SSH keys within Jenkins for Git

need github without username and password

I want to upload a project to the repository, but the problem is that, when I run the command:
$ git push -u origin master
It shows me something like the following:
Username:
Password:
error: The requested URL returned error: 403 while accessing https://github.com/sanxelsanto/books3.git/info/refs
fatal: HTTP request failed
What should I do to avoid such an error message?
For an https address, git will use curl and will need a:
$HOME/.netrc
or (for Windows) a:
%HOME%/_netrc
(with %HOME% defined to any directory you want: HOME isn't defined by default)
Its content:
machine github.com
login <your_github_login>
password <your_github_password>
See "Git - How to use .netrc file on windows to save user and password".
Other parameters are detailed in "Syncing with github" (espacially if you are behind a firewall and need to specify a proxy).
I ran into a similar problem with github and solved it by configuring my git repo over SSH instead of HTTP.
Step1: On the github.com page for your repo you will see three buttons HTTPS, SSH and Git Read Only. Click on "SSH" and copy the contents of the text field. Now there are a couple of ways you can change the configuration:
Step 2a: By editing the config file manually:
Open the .git folder of your repo and edit the config file. Look for [remote "origin"] and set the url config as follows:
[remote "origin"]
#The contents of the text field you copied in Step 1
url = git#github.com:<username>/<projectname>.git
Step 2b: With a git command:
Just run the following command (replace username and projectname variables):
git config remote.origin.url git#github.com:<username>/<projectname>.git
Step3: You can view/confirm the changes with the following command. Look for "remote.origin.url" config:
git config -l