1

Problem

I am working on a job in Jenkins that is utilizing the PowerShell plugin with the purpose of remotely accessing and running utility scripts I have written that I have stored within a Git repository. However, I am having a hard time finding any useful information that demonstrates/explains how to do this. I have even read through most of the wiki for the Git Plugin with hopes that it would have some information.

Question

Can someone assist in demonstrating/explaining how to do the following using PowerShell:

1) Target a specific Git Branch

2) Target a specific folder within a branch

I believe I can figure the rest out from there, but getting to that point has me stumped. Thank you in advance for any and all help.

Brandon
  • 731
  • 2
  • 12
  • 29

1 Answers1

0

In the Source Code Management section, when Git is selected look for the property "Branches to build: Branch Specifier (blank for 'any')". Populate this with the branch you want, e.g. */Example-Branch

Then under additional behaviors, you want to use Sparse Checkout Paths, where the Path property will be the folder to include. e.g. example/folder/path/

BenH
  • 9,766
  • 1
  • 22
  • 35
  • Okay, that's helpful; however, I still need to know how to target these with the PowerShell script. Do you by chance know how to do that as well? – Brandon Aug 29 '17 at 14:08
  • The files from that folder will be copied into your workspace, which will be the working directory. So you can just then call what you need. For example if you wanted to dot source a script named `Example.ps1`, then in a "Windows PowerShell" build step simply add a line `. .\Example.ps1` After you build once, you can also look at what's in your workspace from the Project overview to find what you are looking to run. – BenH Aug 29 '17 at 14:11
  • I am having a problem with the Sparse Checkout Paths... I am getting the error: `Sparse checkout leaves no entry on working directory` . I have tried `branchname/folder/path/` , `*/branchname/folder/path` , `*/folder/path` , and `folder/path` . All produce the same error – Brandon Aug 29 '17 at 14:21
  • @Brandon `folder/path/` is syntax that I have used before without issue. Also looks like that what [others on SO are using](https://stackoverflow.com/questions/10791472/jenkins-and-git-sparse-checkouts) – BenH Aug 29 '17 at 14:30