Build/Package a specific folder from GitHub
Hi,
Aftr the below discussion on Twitter:
Based on https://stackoverflow.com/a/4909267 . Replace 'user.repo' and 'folder1/folder2' with your values. Assume it is a GitHub, other Git VCS should work too. Will not work with Pull requests at least as is. Lets continue on https://help.appveyor.com/discussions/questions … where we can do a proper code snippets.
Try this 'init' stage, 'cmd' mode:
cd %APPVEYOR_BUILD_FOLDER%
git init
git config core.sparseCheckout true
git remote add -f origin git://github.com/user/repo.git > nul 2>&1
echo folder1/folder2/* > .git/info/sparse-checkout
git checkout -qf %APPVEYOR_REPO_COMMIT%
I cannot see that it has actually completed what i wanted it to do, it was successful but there are no real logs for me.
Thanks
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by martinkerr on 21 Nov, 2018 09:42 AM
I am using the below YAML:
version: 1.0.{build}
build_script:
- sh: >-
cd %APPVEYOR_BUILD_FOLDER%
git init
git config core.sparseCheckout true
git remote add -f origin https://github.com/User/Repo.git > nul 2>&1
echo Folder/* > .git/info/sparse-checkout
git checkout -qf %APPVEYOR_REPO_COMMIT%
2 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:02 PM
I am a little bit confused. It was proposed to run in
cmd
mode (assumed you run Windows build). If it is true,- sh:
prefix is no-op and will be simple skipped on Windows. If you run Linux build, environment variable format is$variable
, not%variable%
In any case you can check results of this operation with
tree -if --noreport .
on Linux anddir /s
or alsotree
on Windows.3 Posted by martinkerr on 21 Nov, 2018 02:17 PM
apologies, i selected the wrong option in the UI.
I am now trying the script using the CMD function
Thanks
4 Posted by martinkerr on 21 Nov, 2018 02:28 PM
ok so it ran a little further, but it still clones the whole repo.
Also i get the following error: Command exited with code 128
Any further ideas?
Thanks
5 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:30 PM
Do you use UI or YAML file? If you intend to use UI, do you have
appveyor.yml
in the repo?6 Posted by martinkerr on 21 Nov, 2018 02:34 PM
we usually use YAML file but i was just testing this quickly so was using the UI.
There is no YAML in the repo
7 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:36 PM
OK, please share your config (
Export YAML
in UI) and link to the build.8 Posted by martinkerr on 21 Nov, 2018 02:38 PM
Build - https://ci.appveyor.com/project/ITSupport/client-branding
YAML:
version: 1.0.{build}
build_script:
- cmd: >-
cd %APPVEYOR_BUILD_FOLDER%
git init
git config core.sparseCheckout true
git remote add -f origin https://github.com/BenefexLtd/Client-Branding.git > nul 2>&1
echo SkyscannerChina/* > .git/info/sparse-checkout
git checkout -qf %APPVEYOR_REPO_COMMIT%
after the one folder is cloned, all i want to do is package it up using octopack.exe and push to an Octopus Deploy server.
9 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:41 PM
Ah, I see now, you use
https:
and notgit:
prefix ingit remote add
command10 Posted by martinkerr on 21 Nov, 2018 02:46 PM
OK, i have changed and am trying to build again now
________________________________
11 Posted by martinkerr on 21 Nov, 2018 02:51 PM
it is building now, but it still seems to be cloning the whole repo?
12 Posted by Ilya Finkelshte... on 21 Nov, 2018 02:53 PM
Run
dir /s
after standard clone and after this (for example asinstall
script), and compare the results.13 Posted by martinkerr on 21 Nov, 2018 03:04 PM
i may have been putting the scriptin the wrong place. It was in a build script, i have now changed it to an init scriptin the environment tab.
Building again, so will see what happens
14 Posted by martinkerr on 21 Nov, 2018 03:05 PM
failed with exit code 1
i'm not sure where to put this script.
You are welcome to change the config for me :)
Thanks
15 Posted by Ilya Finkelshte... on 21 Nov, 2018 03:26 PM
I cannot change the config for you, unless you add me as a collaborator. But it is not needed. I checked what you sent one more time, and I see that you set this as a build script. It should be custom clone script. In UI you can find it in General setting tab.
16 Posted by martinkerr on 21 Nov, 2018 03:31 PM
I've put into the clone script, but it still errors.
Error code is 1
17 Posted by Ilya Finkelshte... on 21 Nov, 2018 03:37 PM
Last build I see is running as
init
and not a custom clone script18 Posted by martinkerr on 21 Nov, 2018 03:38 PM
build 1.0.9 was using clone script
19 Posted by Ilya Finkelshte... on 21 Nov, 2018 03:53 PM
I think it is because original sample was for public repo. Replace
git://github.com/BenefexLtd/Client-Branding.git
withgit@github.com:BenefexLtd/Client-Branding.git
and see if this works.20 Posted by martinkerr on 21 Nov, 2018 11:02 PM
Ok so the latest build worked, thank you.
But where will the folder from the repo be stored within the build server now?
And I assume I can use an after build script to run octopack and then push to my Octopus Deploy server?
Also how do I only run this build script when I see a GitHub commit for this particular folder only within the repo?
Thanks
On 21 Nov 2018, at 15:53, Ilya Finkelshteyn <[email blocked]<mailto:[email blocked]>> wrote:
21 Posted by Ilya Finkelshte... on 22 Nov, 2018 12:40 AM
It should be within
APPVEYOR_BUILD_FOLDER
, which is default current directory for build. You can runCD
anddir /s
commands to understand the foolder structure. However as long as you do not change current folder, you can simple use relative path, which is in your case is simple that folder name. And you probably do not need to run octopack to just zip that folder, you can simple add folder to the artifacts with type ofOctopus Package
. In UI it is quite obvious, in YAML it can look like this:22 Posted by martinkerr on 22 Nov, 2018 09:42 AM
Ok, i will try this.
Then can i use the Octopus Deploy deploy steps to push to my octopus deploy server?
Also, how can i only build if something in this particular folder has changed in GitHub?
Thanks
________________________________
23 Posted by Ilya Finkelshte... on 22 Nov, 2018 12:25 PM
Yes, you can use Octopus Deploy steps after that.
To trigger build if only specific folder changed, use this: https://www.appveyor.com/docs/how-to/filtering-commits/#commit-file...
24 Posted by martinkerr on 22 Nov, 2018 01:35 PM
Where in the yml file would the only_commits part go?
Thanks
________________________________
25 Posted by martinkerr on 22 Nov, 2018 02:22 PM
Got it working, thanks!
Another question though... when packaging artifacts can I exclude a file or file type?
Thanks
On 22 Nov 2018, at 13:35, Martin Kerr <[email blocked]<mailto:[email blocked]>> wrote:
Where in the yml file would the only_commits part go?
Thanks
________________________________
26 Posted by martinkerr on 22 Nov, 2018 04:50 PM
Also, when using AppVeyor artifacts, how can a set a version number?
Thanks
________________________________
From: Martin Kerr
Sent: 22 November 2018 14:21:46
To: Ilya Finkelshteyn
Subject: Re: Build/Package a specific folder from GitHub [Questions #30243]
Got it working, thanks!
Another question though... when packaging artifacts can I exclude a file or file type?
Thanks
On 22 Nov 2018, at 13:35, Martin Kerr <[email blocked]<mailto:[email blocked]>> wrote:
Where in the yml file would the only_commits part go?
Thanks
________________________________
27 Posted by Ilya Finkelshte... on 22 Nov, 2018 11:32 PM
You can delete files of specific type recursively from that folder before packaging. It can be part of build script for example. Quick search provides [this](https://blogs.technet.microsoft.com/heyscriptingguy/2006/10/23/how-...] and number of others which gives an idea of how to do that.
Regarding artifact versioning. You can rename the folder to contain version and package it from the script. You can use
APPVEYOR_BUILD_VERSION
environment variable for that.Ilya Finkelshteyn closed this discussion on 23 Jan, 2019 09:05 PM.