Pipeline step is failing with "fatal: reference is not a tree: 679e2fc3c2590f7dbaf64534a325ac60b4dc8689" - jfrog-pipelines

One of my step in my pipeline is failing with the below error:
fatal: reference is not a tree: 679e2fc3c2590f7dbaf64534a325ac60b4dc8689
How do i resolve this error? even after re-triggering the step, it is failing with the same error.

This could be a result of git push --force or git rebase, which deletes the commit and causes the pipeline to lose the pointer to the change and finally not run.
You can resolve this by either doing:
A Reset the resource in JFrog Pipelines and then trigger a run.
Note that if there are several GitRepo resources in the pipeline, this
needs to be done for all of them.
Push another commit so that all the resources are updated automatically.

Related

Bypass branch protection with action and Github app

I have an action, that automatically indexes all files in the repository and creates a csv. Currently this action always creates their own pull request. This creates the annoying need to approve two pull requests per change (the first one with the change itself and the second one with the change in the index.csv file created by the action minutes later).
What I tried now, is creating a Github App, which is added to the "Allow specified actors to bypass required pull requests" in the branch protection and using tibdex/github-app-token#v1 to create a token in the context of the GitHub app.
Unfortunately, it still does not work. I get the following error:
Run echo "Hello World" >> HelloWorld.txt
[main f8445ab] Add unncessary file for testing
1 file changed, 1 insertion(+)
create mode 100644 HelloWorld.txt
remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: error: Required status check "*****" is expected. At least 1 approving review is required by reviewers with write access.
To https://github.com/***/***.git
! [remote rejected] main -> main (protected branch hook declined)
error: failed to push some refs to 'https://github.com/***/***.git'
Error: Process completed with exit code 1.
The code I'm trying to run in the action is the following:
echo "Hello World" >> HelloWorld.txt
git config --global user.email "****"
git config --global user.name "****"
git add .
git commit -m "Add unncessary file for testing"
git push "https://action-name:${{ steps.generate_token.outputs.token }}#github.com/***/***.git"
I know that it is bad practice and breaks the permission concept to be able to do this, but in this case, it is fine for many reasons which go beyond the discussion at this point.
I'm happy for any suggestions on how to achieve this.
Thanks so much in advance

Using env variable github.ref_name doesn't give me branch name

When I use in my workflow github.ref_name it doesn't provide me a branch name from where I triggered this workflow. I get 16/merge. Why? When I use github.ref_type I clearly see that my ref type is branch so why I don't get branch name?
Also it's showing when I use $GITHUB_REF or git symbolic-ref HEAD (and separating refs/heads/ off). Ah and I tried github.event.push.ref but it's not showing me anything.
How to get always branch name from where I triggered the workflow?
For following code:
Run echo running on branch ${GITHUB_REF##*/} ${GITHUB_REF}
When your workflow runs becuase of push event you will get:
running on branch main refs/heads/main
But for pulr request event it would be:
running on branch merge refs/pull/3/merge
Why's that?
If the repository is on GitHub and you have any Pull Requests that have been opened, you’ll get these references that are prefixed with refs/pull/. These are basically branches, but since they’re not under refs/heads/ you don’t get them normally when you clone or fetch from the server — the process of fetching ignores them normally.
You can also check this question here

Circumvent pull request for script

We use Jalopy to reformat the code. On jenkins/svn, we checked out, formatted and commited again. Now on bamboo/stash, we want to do the same.
We set up this restriction for the master branch:
Prevent changes without a pull request (Everyone)
(AFAIK, it is not possible, to exclude certain users from this rule, is it?)
Now, as expected, when we try to push the formatted sources, we get this error:
remote: Branch refs/heads/master can only be modified through pull requests.
remote: Check your branch permissions configuration with the project administrator.
remote: ----------------------------------------------------
remote:
To ssh://git#mystash.com/proj/proj1.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'ssh://git#mystash.com/proj/proj1.git'
Any suggestions on how we can keep the enforcement for pull requests, while still being able to push directly to master from a Bamboo script? Or any better approach?
That is currently correct ... kind of. The Stash UI doesn't provide a way to set this (or see if you have) at the moment. However, the REST API will actually let you set branch permissions and specify users who are exempt. For details, see this comment on the feature suggestion to add full support.

Prevent mercurial push during a jenkins build

I have a jenkins job that runs some tests on a mercurial repo, and if successful tags the local repo with a 'stable' tag and then pushes this back to the main repo. The issue I'm having is that if someone pushes changesets while the build is running, then I cannot push the 'stable' tag.
I was wondering if there was a way to set the remote repo to read-only while the build is running, then make it 'push-able' once the build finishes?
Thanks,
Vackar
Preventing the push is probably not what you want (and it's almost pretty much impossible). The promise of a DVCS like Mercurial or git is that there's no locking -- it's a step forward.
Have you considered having Jenkins just pull and update before it merges? You can still tag the proper revision. Something like this:
jenkins checks out the code and notes the revision id it's building
jenkins does the build, runs the tests, etc. and everything goes well
jenkins does a hg pull to get the latest from the server
jenkins does a hg tag -m "build number $BUILD_NUMBER" --revision X --force stable
jenkins does a hg push
Then there's (almost) no time between that final pull, tag, and push, but the tag still goes on the revision that was actually build -- because you saved that revision hash id from when you first pulled.
I've just been looking for something similar. In our case, Jenkins is performing a merge, running an extensive suite of tests and once they all pass, pushing the merged code back to the repository. So it takes ~1 hour and fails if a developer pushes while the job is executing (it can't do the final push).
I couldn't find a ready-made solution, so ended up writing a mercurial hook which checks whether the job is building (using the REST API) before allowing the push.
You'll need access to your remote mercurial repository, but other than that, it's not too complex.
Add the following to your-remote-repo/.hg/hgrc:
[hooks]
pretxnchangegroup.DisablePushDuringJenkinsBuild= python:.hg/disable_push_if_building_hook.py:check_jenkins
[jenkins]
url=http://path-to-jenkins
jobs=jenkins-job-name[,comma-separated, for-multiple, jobs]
And make sure this python script is in your-remote-repo/.hg/
import json, urllib2
from mercurial import util
TEN_SECONDS = 10
def check_jenkins(ui, repo, node, **kwargs):
jenkins_url = ui.config('jenkins', 'url', default=None, untrusted=False)
jenkins_jobs = ui.config('jenkins', 'jobs', default=None, untrusted=False)
if not jenkins_url:
raise util.Abort('Jenkins hook has not been configured correctly. Cannot find Jenkins url in .hg/hgrc.')
if not jenkins_jobs:
raise util.Abort('Jenkins hook has not been configured correctly. Cannot find Jenkins jobs in .hg/hgrc.')
jenkins_jobs = [x.strip() for x in jenkins_jobs.split(',')]
for job in jenkins_jobs:
job_url = jenkins_url + '/job/' + job + '/lastBuild/api/json'
ui.write('Checking if job is running at URL: %s\n' % job_url)
try:
job_metadata = json.load(urllib2.urlopen(job_url, timeout = TEN_SECONDS))
if 'building' in job_metadata and job_metadata['building']:
raise util.Abort('Jenkins build "%s" is in progress. Pushing is disabled until it completes.' % job_metadata['fullDisplayName'])
except urllib2.URLError, e:
raise util.Abort('Error while trying to poll Jenkins: "%s"' % e)
return False # Everything is OK, push can be accepted

How to push to a local remote?

I'm having a hard time pushing my commits to a remote repository with libgit2sharp. Using the git bash it works fine.
The remote is addressed via UNC like "//computer_name/remote.git". So it's a folder on a machine in the local network which has an accessible folder.
Cloning it to a local repo with libgit2sharp worked just fine and constructing a remote was successful too with
Remote remote = localrepo.Network.Remotes["origin"];
Now when I try pushing to the remote with:
localrepo.Network.Push(remote, "HEAD", "origin");
I get the exception in git_push_add_refspec() in Proxy.cs
An error was raised by libgit2. Category = Invalid (Error).
Not a valid reference 'origin'
So then I tried:
repo.Network.Push(remote, "HEAD", #"refs/remotes/origin/master");
and got the exception in git_push_finish() in Proxy.cs
An error was raised by libgit2. Category = Net (Error).
Remote transport doesn't support push.
Is there a right way to do this or is there a support problem for my usecase?
Thanks in advance!
[UPDATE]
Now my command looks like this
repo.Network.Push(remote, "HEAD", #"refs/remote/origin/master", pushStErrHnd, null);
The PushStatusErrorHandler has only one line of code in which it should write the PushErrorStatus to console. But console remains blank and then the above exception occurs.
[UPDATE 2]
The static variable Repository.Version was 0.9.5 when I experienced the above.
As nulltoken has already mentioned, local push has just recently been added. You will need to make sure that you have a recent LibGit2Sharp build (you will need LibGit2Sharp containing commit 547a6bd, committed on March 12)
Also, there is a slight mistake in the API usage. The destination reference should be the reference to update on the remote (e.g. #"refs/remote/origin/master" should probably be #"refs/heads/master").
Push to a local repository has been recently added to libgit2 (see PR #1406) and eventually embedded in LibGit2Sharp. However, this feature hasn't been properly tested yet.
In order to try and help you, could you please update your questions with the answers to the few questions below:
Push accept an additional parameter to give more information about issues: onPushStatusError. Could you please provide the output of each potential PushStatusErrors?
You state "Cloning it to a local repo worked". How did you perform the clone? Through git? Through LibGit2Sharp?
What happens if you change the url of the remote to a file URI format (eg. file://computer_name/remote.git)?
UPDATE
The amazing #yorah is working on a Pull Request to enhance the test coverage regarding your scenario.
Cloning from a local repository
Adding a new Commit
Pushing the newly created commit
Retrieving the list of the remote references