Jenkins not building github project [duplicate] - github

Just installed Jenkins in Ubuntu 12.04 and I wanted to create a simple build that just clones a project and builds it.
It fails because it cannot tag. It cannot tag because it errors out saying "tell me who you are" apparently because I didn't set git settings UserName and UserEmail.
But, I should not need to set those, Jenkins is going to just clone the repository, why does it need the credentials if it's not going to push changes, why does it need to do a tag at all?
Full error log is:
Started by user anonymous
Checkout:workspace / /var/lib/jenkins/jobs/Foo.Bar.Baz/workspace - hudson.remoting.LocalChannel#38e609c9
Using strategy: Default
Cloning the remote Git repository
Cloning repository origin
Fetching upstream changes from git#mygithost.mydomain.local:foo-bar-baz/foo-bar-baz.git
Seen branch in repository origin/1.0
Seen branch in repository origin/1.5.4
Seen branch in repository origin/HEAD
Seen branch in repository origin/master
Commencing build of Revision 479d37776b46283a946dd395c1ea78f18c0b97c7 (origin/1.0)
Checking out Revision 479d37776b46283a946dd395c1ea78f18c0b97c7 (origin/1.0)
FATAL: Could not apply tag jenkins-Foo.Bar.Baz-2
hudson.plugins.git.GitException: Could not apply tag jenkins-Foo.Bar.Baz-2
at hudson.plugins.git.GitAPI.tag(GitAPI.java:737)
at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1320)
at hudson.plugins.git.GitSCM$4.invoke(GitSCM.java:1268)
at hudson.FilePath.act(FilePath.java:758)
at hudson.FilePath.act(FilePath.java:740)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1268)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1193)
at hudson.model.AbstractBuild$AbstractRunner.checkout(AbstractBuild.java:565)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:453)
at hudson.model.Run.run(Run.java:1376)
at hudson.matrix.MatrixBuild.run(MatrixBuild.java:220)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:175)
at hudson.model.OneOffExecutor.run(OneOffExecutor.java:66)
Caused by: hudson.plugins.git.GitException: Command "git tag -a -f -m Jenkins Build #2 jenkins-Foo.Bar.Baz-2" returned status code 128:
stdout:
stderr:
*** Please tell me who you are.
Run
git config --global user.email "you#example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: empty ident <jenkins#somehostname.(none)> not allowed
at hudson.plugins.git.GitAPI.launchCommandIn(GitAPI.java:786)
at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:748)
at hudson.plugins.git.GitAPI.launchCommand(GitAPI.java:758)
at hudson.plugins.git.GitAPI.tag(GitAPI.java:735)
... 13 more

The idea of tagging when pulling/cloning a repo is common to most Build Scheduler out there:
Hudson-Jenkins, but also CruiseControl (The build label determined by the labelincrementer), or RTC Jazz Build Engine (where they are called "snapshots").
The idea is to set a persistent record of the input to a build.
That way, the code you are pulling, even if it wasn't tagged, is tagged automatically for you by the build scheduler, in order to be able to get back to that specific build later.
If that policy (always tagging before a build) is set, then Jenkins will need to know who you are in order to make a git tag (it is a git object with an author attached to it: user.name and user.email).
However, as mentioned in " Why hudson/jenkins tries to make commit? ":
Checks "Skip internal tag" config under "Advanced..." in section "Source code management".
That should avoid that extra tagging step you appear to not need.

As for how to set user.email and user.name,
In jenkins, go to "Manage Jenkins" > "Configure System"
and scroll down to "Git plugin" and there you will find
enter your email and name, you're good to go.

I used the solution above by iecanfly . Using my git user name and password didnt work , I
entered
username : jenkins
email : jenkins#localhost
That fixed the issue.

You can also SSH into Jenkins and navigate over to the workspace directory, and then you can just run the git config user.name and user.email commands normally.

If you are running Jenkins in a Docker container, you'd need to exec into the container docker exec -it <CONTAINER_ID> sh then run the suggested git commands with your email and name.

Related

Authentication failed and unable to link visual studio to git repository

I am trying to set up to build my first website and have been following an online tutorial. When trying to link visual studio and my GitHub repository, this is the message I get:
`
samanthacanela#samanthas-air Canela Street Art % git commit -m "initialized git repository"
[main 3a08e0a] initialized git repository
2 files changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 about.html
rename homepage.html => home.html (100%)
samanthacanela#samanthas-air Canela Street Art % git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
To have this happen automatically for branches without a tracking
upstream, see 'push.autoSetupRemote' in 'git help config'.
samanthacanela#samanthas-air Canela Street Art % git push --set-upstream origin main
The authenticity of host 'github.com (140.82.112.3)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
git#github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
samanthacanela#samanthas-air Canela Street Art %
`
I'm an absolute beginner. What the hell am I doing wrong?
I was following along a tutorial and they lost me.
Based on my understanding, I can see that you may haven't setup the origin remote URI. To fix that issue, you'll need to follow these steps.
Logging into git (If you aren't already)
Run these commands to set your display name and email when pushing:-
$ git config --global user.name "Your name here"
$ git config --global user.email "your_email#example.com"
Using HTTPS access method (recommended)
Using GitHub CLI, you can run $ git auth login and follow the steps to login.
Or if you're using GCM (Git Credential Manager)* refer to this article by GitHub
* GCM is another way to store your credentials securely and connect to GitHub over HTTPS. With GCM, you don't have to manually create and store a personal access token, as GCM manages authentication on your behalf, including 2FA (two-factor authentication).
Using SSH access method
If you clone with SSH, you must generate SSH keys on each computer you use to push or pull from GitHub. For more information, see "Generating a new SSH key."
Setting up your repository
** Make sure to run these commands inside your git environment and not globally.
#Set a new remote
git remote add origin github.com/example/example.git
#Verify new remote
git remote -v
Basically, a common cause for an error after following these steps is cloning using HTTPS method instead of SSH. You can correct this by going to your repository, clicking "Clone or download", then clicking the "Use SSH" button above the URL field and updating the URL of your origin remote like this:
$ git remote set-url origin git#github.com:ex-user/example.git
And that forces the source to be SSH.
If this still gives you an error, please refer to this answer.
For more help, refer to this document.

In codebuild with github push event, git show -s errors with message fatal: unable to parse commit <sha>

I am trying to read the commit message in my codebuild script when I receive a push event from github. My main goal is to skip the build with a message that has skip ci in it like travis or other ci tools.
git show -s --format=%s (or git show with any options) results in:
error: Could not read <previous SHA here>
fatal: unable to parse commit <previous SHA here>
git log -1 --pretty=%s also results in an error.
I used git rev-parse --is-shallow-repository to see that it is a shallow repository and I have tried to use git fetch --unshallow but that resulted in this message:
error in object: unshallow <SHA from a couple months ago>.
Some git commands that I know do work
git commit and git push (after setting up credentials)
git checkout $branch_name
git pull (after setting up credentials)
git status
Does anyone know how to read a commit message from a push event in codebuild?
I would also like to make a note that the Source Version in the aws console is the commit SHA. When I manually click start build and provide a branch name git show --<options> works
I realized that my issue was because in my aws codebuild project configuration, there is a git clone depth option and it was set to "1". I set it to "full" and it now works
git cat-file will print details about just the one commit, and you can pluck the commit message from the output.
$ git cat-file -p $CODEBUILD_SOURCE_VERSION
tree de60715e166beccca8d3d8b545ad38ba4a90e41b
parent 2645cf2643845f34032cf9b8996f8ad141425462
author [Me] <...> 1654272805 -0400
committer [Me] <...> 1654272805 -0400
This is the subject line of the commit
The remainder of the commit body is printed below. I'm specifying
this to say that it won't necessarily be straightforward to head
and tail this output, for example.
This will also work in both cases of a commit hash and a branch name.
I didn't want to change the git clone depth to full for several reasons. The problem with git show, git log, and others is that they're porcelain commands that refer to commits other than the one you're looking at. git cat-file is a plumbing command so it's not doing anything you're not expecting, and should always work as long as you pass a valid ref.

How to resolve "fatal: unable to access " error

I'm a beginner to GitHub.I need to send a pull request to the master branch.
when i typed the code
git push origin master
It gives me the error
fatal: unable to access
'https://github.com/www-prolificme-com/mahawiki/': The requested URL
returned error: 403
Updated
You mentioned you are trying to pull from git but the command is git push. Anyways, most probably you are getting this error because your repo url is not set locally.
If this is the first time you are sending git request from your system, you might want to setup your username by git config --global user.name "John Doe"
If you have already used git on your system, try checking the git configuration on your system using git config --list command to check whether your repo URL is setup or not.
If the url is not setup run git remote set-url origin https://github.com/www-prolificme-com/mahawiki/
Run git remote -v to verify if your url is setup
git add .
git commit -m "your message"
git push origin master
Remove/Update the saved credentials:
Click Start
Search for 'Credential Manager'
Select 'Windows Credentials Manager' > 'Windows Credentials'
Search for the credentials that you want to remove/update
Click on the credential entry > Click 'Edit' or 'Remove'
your repo is not setting locally
so, you seemed crash message
first
git config --list
to showing your git repo set list
and
git remote set-url origin <your git repo address>
to access git repo and git add . to add your files to git container
git commit -m "your git commit message"
this is your git commit message version or anything possible
git push origin master
finally your files pushing on git repo
it's done!
try it
I got this same problem then I try to this below command.
step 1:
git config --global user.email "user email"
step 2:
git config --global user.name "user name"
After running those commands, you can use this command to push your code:
git push origin master
Even if you set all credentials and other setups in the local machine, you might face this problem.
Currently, GitHub uses 'personal access token' so when or after creating personal access token you must check the Select scopes.
You select all you need and then push again.
It will be pushed successfully.
If nothing working please check if you have checked the below checkboxes while creating token

Commit with wrong username to github

If I committed to github with a wrong local credentials (username and password), will it be possible to change the committer name on github? This issue can happen if you have two git accounts! By the way I'n not asking how to reconfigure your local git account.
1- configure your new username and email with
change username: git config username.user <username>
change email: git config username.email <email>
2- run this command git commit --amend -C HEAD --reset-author
3- run this command git push --force
This will change the other in the last commit.
You can change the last commit locally with
git commit --amend --author="Author Name <email#address.com>"
Then do a
git push --force
This will force the authored commit over the top of the old one.
In my case, I have two GitHub accounts (A and B). I had created a repository using A and in local while configuring git,used email id of B account. So whenever I was pushing the code from my local, git was inferring the account B as author. So even though, I had used credentials of Account A, it was still showing author B for all commits done using local machine.
Fix
Configured email in local for Account A and issue got resolved. Further, all commits were showing correct author as A.
For commits to be linked to your Github account, your email or username in your local git configuration should match the one you have on Github.
Check your current Git configuration:
git config --global --list
Update your email or your username as the same value in your Github account:
git config --global user.email "xyz#gmail.com"
git config --global user.name XYZ
git config --global user.username xyz
(Optional) If you want to change previous commits to reflect your new email/username. Be careful, though, if the repository have a multi-user commits, this will change all commits to have the same new author.
git filter-branch -f --env-filter "GIT_AUTHOR_NAME='Newname'; GIT_AUTHOR_EMAIL='new#email'; GIT_COMMITTER_NAME='Newname'; GIT_COMMITTER_EMAIL='new#email';" HEAD

problem in pushing to github

I have created a repository on github named pygame. Created a clone and added files and commited.but when I attempt to push I receive the following error:
git push -u origin master
error: The requested URL returned error: 403 while accessing https://github.com/amalapk/pygame/info/refs
fatal: HTTP request failed
I can ssh to git#github.com and receive the notice that I logged in successfully, but can't push to my repository.
I recently experienced this problem when setting up a new clone of my github project.
You need to include your username in the URL to your project, in the form
https://user#github.com/project/...
For example, the URL provided for my test github is this:
https://github.com/jdblair/test.git
If I add my username to it, like this, then I'm able to push and pull from github with no problem:
https://jdblair#github.com/jdblair/test.git
It is easiest to use the URL that contains the username starting from when you clone a project.
You can change the URL for an existing project like this:
git remote set-url origin https://user#github.com/project/foo/bar.git
You can use the ssh authentication instead if you want, but that's a separate setup process.
Github now is asking us to use git 1.7.10 or later:
https://help.github.com/articles/error-the-requested-url-returned-error-403
The GitHub Remote page mentions the read/write addresses for a repo:
Make sure your clone address is like:
https://github.com/username/yourRepo.git
And that you have defined:
git config --global user.name "Firstname Lastname"
git config --global user.email "your_email#youremail.com"
Should you use a git address (without ssh), you would also need:
git config --global github.user username
git config --global github.token 0123456789yourf0123456789token # no longer needed
(with your token coming from “Account Settings” > Click “Account Admin.”)
Update 2013: you still can generate a token (see "Creating an access token for command-line use"), but you would use it as a password for https url.
Actually, if you activate the 2FA (two-factor authentication) mechanism on GitHub, you will need a token for your https url (because your regular password would trigger the second-step verification).
See "Configure Git clients, like GitHub for Windows, to not ask for authentication"
See more at "Which remote URL should I use?".
It's all in the remote.
Change your current remote from https://github.com/amalapk/pygame.git to git#github.com:amalapk/pygame.git and enjoy.
To do this... (assuming your current remote is called origin)
git remote set-url origin git#github.com:amalapk/pygame.git
In my case getting rid of such error message was resolved this way:
Person was simply added to github repository as a colaborator.
Thats it - error vanished magically.
Committing to github from server this is what worked for me in the terminal or git bash
To create a remote to github.com try:
git remote add origin https://put your username here#github.com/put your git username here/put your repository name here
To change the remote just do:
git remote set-url origin https://put your username here#github.com/put your git username here/the name of your repository here
Please follow the instructions on http://help.github.com/create-a-repo/
You have cloned your repository with the public read only url.
RTFM