What I’m trying to do is get the name of the repository used in a Netlify deploy.
I have a GitHub repo which I offer through a ‘Deploy to netlify’ button. When someone uses it they are given the option to name the clone that Netlify creates for their GitHub repository.
We always set some variables that are available during build:
You could, during build, read those variables and do “anything” with them - including make a function output their values (note that the variables aren’t available directly in functions - you’d have to interpolate the values during build). But, you could also create a static file with that information to keep things simpler, instead, since you’re already interpolating values programatically
Thank you for the reply. It got me thinking and I was able to come up with something that will work.
I made a netlify.toml file with the following:
[build]
# build command adds environmental variables to a yml file on build
command = 'printf "repo: %s" "$REPOSITORY_URL" > _data/netlify_build_env_vars.yml; jekyll build'
This creates a file I can read from in addition to doing the build:
I had to put this _data/netlify_build_env_vars.yml in place before it would work. (The command itself created the file for me when testing locally.)
Anyway, It works!
This is a Jekyll project for anyone interested. I thought I should mention that, as the jekyll-netlify Gem is no longer up to date and this solution may be helpful.