Jenkins List Files of Git Branch

19 views
Skip to first unread message

Ajay Sharma

unread,
Oct 11, 2019, 3:37:34 AM10/11/19
to Jenkins Users
Hi Everyone, Good Morning.

Request any ones help to List All FILES from the GIT BRANCH.  
I am trying to first list Branches of a GIT REPO, then list the files of the BRANCH. 

I am facing problem while listing files of the BRANCH. 

I have used this code List files Of the GIT REPO with   Extended Choice Parameter

def gettags = ("git ls-remote -t -h http://pramod:username...@10.112.78.152/pramod/automaticjobs.git").execute()
return gettags.text.readLines().collect { 
  it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}

BUT this code is not working for Listing the Files of the GIT BRANCH. 

def gettags = ("git ls-remote -t -h http://pramod:username...@10.112.78.152/pramod/automaticjobs.git -r {env.Branches}").execute()
return gettags.text.readLines().collect { 
  it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}



Mark Waite

unread,
Oct 11, 2019, 6:42:14 PM10/11/19
to Jenkins Users
The git ls-remote command is not allowed to list remote files, only remote references (branches and tags).

Git providers (GitHub, Bitbucket, Gitea, Assembla, Beanstalk, Gitlab, etc.) generally provide one or more REST API's that will list remote files in a branch.


On Thursday, October 10, 2019 at 11:37:34 PM UTC-8, Ajay Sharma wrote:
Hi Everyone, Good Morning.

Request any ones help to List All FILES from the GIT BRANCH.  
I am trying to first list Branches of a GIT REPO, then list the files of the BRANCH. 

I am facing problem while listing files of the BRANCH. 

I have used this code List files Of the GIT REPO with   Extended Choice Parameter

def gettags = ("git ls-remote -t -h http://pramod:username.pass...@10.112.78.152/pramod/automaticjobs.git").execute()
return gettags.text.readLines().collect { 
  it.split()[1].replaceAll('refs/heads/', '').replaceAll('refs/tags/', '').replaceAll("\\^\\{\\}", '')
}

Ajay Sharma

unread,
Oct 11, 2019, 7:25:16 PM10/11/19
to Jenkins Users
Hi Mark, Let me check for the GITHUB REST API's. Thanks for the reply. 
Reply all
Reply to author
Forward
0 new messages