zola1986
zola1986

Reputation: 1

Git show-branch command returns different output in Jenkins job

the "git show-branch" command returns from local clone the commit history of the current branch, including its parent branch:

[me@server project]$ git show-branch
! [branch1] Commit 1
 * [branch2] Commit 2
  ! [main] Minor fix
---
 *  [branch2] Commit 2
+*  [branch1] Commit 1
+*+ [main] Minor fix

I have a Jenkins job, which checks out the code similar to this:

checkout ([
    $class: 'GitSCM',
    branches: [[name: '*/*']],
    doGenerateSubmoduleConfigurations: false,
    extensions: [],
    submoduleCfg: [],
    userRemoteConfigs: [[
        credentialsId: 'id123',
        url: 'https://url123.com/repo.git'
    ]]
])

Now, if I'm checking out a specific branch and issueing the "git show-branch" command from Jenkins, the result contains only the commit of the current branch, and nothing from the parent.

[Pipeline] bat

C:\jenkins\workspace\project>git show-branch
[branch2] Commit 2
[Pipeline]

As you see I am not using shallow checkout, but the history is still missing. The git versions are the same. I haven't found any setting regarding showbranch.default, see https://git-scm.com/docs/git-show-branch which could have affection.

Would you please advise? Many thanks.

Upvotes: 0

Views: 61

Answers (1)

criztovyl
criztovyl

Reputation: 819

AFAK Jenkins does not create local branches (refs/heads/) for all remote ones (refs/remotes/.../); but show-branch only shows local ones.

As the linked documentation says (emphasis mine):

git show-branch [...]
      [(<rev> | <glob>)…​]

Shows the commit ancestry graph starting from the commits named with <rev>s or <glob>s (or all refs under refs/heads and/or refs/tags) semi-visually.

Maybe on Jenkins git show-branch refs/remotes/origin/* does what you want?

But be careful, after initial checkout Jenkins will only update the ref for the branch being currently built!


Edit:

The branches: [[name: "*/*"]] most likely does not do what you want, it will only determine a single branch from those matched, and only that branch will be updated.

See also Why does Jenkins allow specifying multiple git branches?.

Upvotes: 1

Related Questions