Cli: Set Deploy Context / Branch from CLI

Created on 28 Mar 2019  Â·  37Comments  Â·  Source: netlify/cli

Not sure if this is a question or a recommendation at this point.

I'm trying to create a dedicated staging (pre-prod) environment: e.g. staging--myproject.netlify.com.

I am manually deploying in my GitLab pipeline using netlify deploy. However, with the CLI it seems I can only deploy to (i) my production URL or (ii) a dynamic URL.

Ideally, I'd like to specify the context similar to netlify deploy --context=staging to deploy to a dedicated URL.

Thank you for any insight.

feature

Most helpful comment

[email protected] has just been released with support for branch specific deploys. Please update and try it out with netlify deploy -b test

All 37 comments

It's an interesting idea and suggestion. I like it.

just fwiw we have some concerns on our end about how this may conflict with other features and considerations we have yet to announce - so no promises on how quickly we will incorporate this. but in principle i agree this is a useful thing to have. the devil is in the details.

We need that too!

Out use case is that we use CircleCI for everything. And we use Netlify to host our static frontend. So, effectively we're running out builds in 2 places (duplication), while it would be really nice to use CircleCI for everything and just send files over to Netlify.

While doing that we're missing "Branch deploy" feature which is really nice.

Very much would appreciate this functionality as well.

Just adding to this with my current situation...

I am making a group portfolio site for a graduating design class. I am making a site with GatsbyJS, which creates image thumbnails on build. This site has many fairly-large images, so it must sometimes be deployed with the CLI if there are updates that the cache isn't being cycled from (say, new images under the same name as old ones). Small updates tend to work okay, because I'm using gatsby-plugin-netlify-cache. This works fine, but only so long as the master branch is the one being deployed to the prod URL, so that I can deploy from the CLI if there is any issue updating the cache.

This leads to my current issue: I have now deployed a "coming soon" countdown to the main URL and put the master behind a branch deploy. Unfortunately, this means I can't find a way to deploy the master from the CLI to its branch URL. I can only deploy either a preview or to --prod. Unfortunately, deploying to --prod puts the work-in-progress master branch onto the public URL.

My current workaround is to simply update the filename of any changed image ... but this isn't a great solution, and I worry if one of the pages on the site adds a lot of images (which might exceed the Netlify build time in thumbnail creation time), I might be stuck without a way to update the master branch deploy.

This is a bit of a complex issue and maybe an edge case, but I hope it shows a scenario in which an option like netlify deploy --context=staging would be useful. I'm hoping this is something that is available (or solved by some other feature) in the future!

acknowledged the importance of this.

We would like to run our end-to-end tests against deploy preview URLs, so passing the context/branch into the deploy command would help us as well to automate that process.

should inform customers in addition to this thread:

I'm using Gitlab CI and facing the same problem.
Any status update?

Got the latest version of the CLI

  $ netlify deploy

OPTIONS
  -a, --auth=auth            Netlify auth token to deploy with
  -d, --dir=dir              Specify a folder to deploy
  -f, --functions=functions  Specify a functions folder to deploy
  -m, --message=message      A short message to include in the deploy log
  -o, --open                 Open site after deploy
  -p, --prod                 Deploy to production
  -s, --site=site            A site ID to deploy to
  --json                     Output deployment data as JSON
  --silent                   Silence CLI output
  --timeout=timeout          Timeout to wait for deployment to finish

No, no progress so far

I wrote a guide Deploy a static website to Netlify using GitLab's CI/CD pipeline.

Until now I was successfully only deploying the master branch build to the netlify production deploy:

# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:10

stages:
  - test
  - deploy

# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
  paths:
  - node_modules/

before_script:
  - npm install hexo-cli -g
  - npm install

test:
  stage: test
  script:
    - hexo generate
  except:
    - master

pages:
  stage: deploy
  script:
    - hexo generate
    - npm install netlify-cli -g
    - netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod --dir public/
  artifacts:
    paths:
      - public
  only:
    - master

But now I want to create a preview deploy for any other branches, so I moved my Gitlab CI config to

# Official framework image. Look for the different tagged releases at:
# https://hub.docker.com/r/library/node/tags/
image: node:10

stages:
  - test
  - deploy

# This folder is cached between builds
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
cache:
  paths:
  - node_modules/

before_script:
  - npm install hexo-cli netlify-cli -g
  - npm install

test:
  stage: test
  script:
    - hexo generate
    # Wihthout the --prod option this deploys only a preview
    - netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --dir public/
  except:
    - master

pages:
  stage: deploy
  script:
    - hexo generate
    - netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --prod --dir public/
  artifacts:
    paths:
      - public
  only:
    - master

So in the test job just adding a netlify deploy without --prod so it won't be pushed to production and only generating a preview.

But unfortunately the job always end like this:

765 $ netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --dir public/
766 Logging into your Netlify account...
767 Opening https://app.netlify.com/authorize?response_type=ticket&ticket=XXX
768 ---------------------------
769 Error: Unable to open browser automatically
770 Please open your browser & open the URL below to login:
771 https://app.netlify.com/authorize?response_type=ticket&ticket=XXX
772 ---------------------------
773 You are now logged into your Netlify account!
774 Run netlify status for account details
775 To see all available commands run: netlify help
776  ›   Error: Not Found
777 ERROR: Job failed: exit code 1

$NETLIFY_SITE_ID and $NETLIFY_AUTH_TOKEN were already stuffed for the master branch but here it seems this new branch job can't use them or need to authenticate once more. The only cached path is node_modules so this is not a cache issue. I don't understand why it need to manually authenticate again, and why even when I manually open the new authorization page and accept it continue to fails. Il try to add a netlify status from the CI to see what is happening here.

Actually all preview URLs from the production are looking like https://5dfe3d1423a010917b502c04--rawsec-blog.netlify.com/ and I don't care not having a custom https://stagging--rawsec-blog.netlify.com/ URL. I should just be able to see a difference bewteen production and non-production deploy thanks to the --prod option from netlify CLI and could optionally add more context dependent information with the --message option.

Edit I read the only working workaround was to create a separate netlify project, see https://medium.com/js-dojo/deploying-vue-js-to-netlify-using-gitlab-continuous-integration-pipeline-1529a2bbf170#3e81 to get a proper stagging preview which is very heavy in term of process.

Also I should add I'm only using Gitlab-CI and netlify CLI, not the integrated netlify git link feature.

Nice, seems to be some movement on this issue. We're also coming from Gitlab, and would like to use similar functionality as branch deploy, but run from the Gitlab CI via the Netlify CLI. We have many other jobs we want to run (test/lint/e2e/etc), so it feels better to keep it in the same place.

This issue has been raised internally with the API team to implement an endpoint that would allow creating branch deploys. Please hold on.

Thanks for the update! Is there any rough ETA - ie it'll be a matter of days/weeks/months?

We don't have an ETA at the moment but since this is a highly requested feature we'll prioritize it and report back when we have a plan.

@RaeesBhatti this feature would be a blessing for our team since our code is on Bitbucket and we don't have access to deploy previews as a result. We're really stuck at the moment. Just an API endpoint would unblock us.

Any update on this issue.

Yes! This would be a life saver for projects/companies that rely on netlify but have to, for whatever business/security reasons, have complete control of their deploy pipeline/git repository.

Right now i have to use one site per branch it kinda overflow my netlify dashboard, i'd be interested in this

Thank you 🎉

[email protected] has just been released with support for branch specific deploys. Please update and try it out with netlify deploy -b test

Thanks for the other PR as well! https://github.com/netlify/js-client/pull/105

branch param also added to API docs here: https://open-api.netlify.com/#operation/createSiteDeploy

Exciting update! Now we can have nice aliases for our deploys.

I did some testing and noticed it doesn't seem to work with --trigger to trigger a branch deploy, or split-testing (when deploying to the branch in the split test).

Is that accurate? Or am I doing something wrong?

@rajington Yes --trigger hits a different API endpoint and works differently that normal deploy. That endpoint doesn't yet have a branch parameter. I will look into this

seems we can't yet link a domain ?

image

@rajington Yes --trigger hits a different API endpoint and works differently that normal deploy. That endpoint doesn't yet have a branch parameter. I will look into this

Thanks, not supporting trigger is not a huge problem or anything.

I was guessing split-testing is a whole other can of worms and not really part of this "alias" stuff, is that accurate? Also completely understand if it's not a priority, prob not many people are using split-testing with CLI deploys.

We're considering renaming the recently introduced --branch flag to --alias since people might expect --branch to be similar in functionality to the Git branches. It isn't similar to Git branches and is only useful to pretty URL's.
Please provide your feedback via up or down votes to this comment. Should --branch be renamed to --alias?

The author is considering the same thing for the GitHub Action! https://github.com/nwtgck/actions-netlify/pull/178#issuecomment-638777483

I'm not sure if I understand the --branch flag correctly.

Currently I have a custom domain, shopit.space, in which the redux branch will be deployed to redux.shopit.space. When I execute netlify deploy -b redux, here is the GitHub Actions logs.

$ netlify deploy --dir=build --branch=redux
Deploy path:        /home/runner/work/react-ecomm-site/react-ecomm-site/build
Configuration path: /home/runner/work/react-ecomm-site/react-ecomm-site/netlify.toml
Deploying to draft URL...
- Hashing files...
✔ Finished hashing 41 files
- CDN diffing files...
✔ CDN requesting 16 files
- Uploading 16 files
✔ Finished uploading 16 assets
- Waiting for deploy to go live...
✔ Deploy is live!

Logs:              https://app.netlify.com/sites/react-ecomm/deploys/5edcdff41311f812dcd11514
Website Draft URL: https://redux--react-ecomm.netlify.app

I was under the impression that it will deploy to redux.shopit.space but apparently it does not. It this behavior expected?

We don't "deploy to" hostnames like that; we can show deploys at hostnames
like that, once configured. You seem to have it configured correctly, here:

https://app.netlify.com/sites/react-ecomm/settings/domain#branch-subdomains

Does https://redux.shopit.space not work as you're intending? I can see it
serves that site, but can't tell if it's the content you're expecting or
not.

TL;DR that notification will use our internal name, but you should be able
to use the other one once it is (as it is on your site) correctly
configured as a branch subdomain and the SSL certificate matches, which
yours does (*.shopit.space)

On Sun, Jun 7, 2020 at 5:29 AM Malcolm Kee notifications@github.com wrote:

I'm not sure if I understand the --branch flag correctly.

Currently I have a custom domain, shopit.space, in which the redux branch
will be deployed to redux.shopit.space. When I execute netlify deploy -b
redux, what I get is the following logs:

Logs: https://app.netlify.com/sites/react-ecomm/deploys/5edcdbcdeb4b84deeb7c7203
Website Draft URL: https://redux--react-ecomm.netlify.app

I was under the impression that it will deploy to redux.shopit.space but
apparently it does not. It this behavior expected?

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/netlify/cli/issues/275#issuecomment-640211228, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AABX5IBYCP7MCLQQ5G4LAM3RVOBZXANCNFSM4HCEPHVA
.

@fool the ui don't allow me to have a subdomain without linking the site to a git repository :/

Not entirely surprising. Shall I try unlinking the git repo to see if it
still works (won't show up in the UI, but that is not the purpose of this
feature request - it's to get it working :))

On Mon, Jun 8, 2020 at 1:59 PM Sceat notifications@github.com wrote:

@fool https://github.com/fool the ui don't allow me to have a subdomain
without linking the site to a git repository :/

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/netlify/cli/issues/275#issuecomment-640883461, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AABX5IFA22M73CKPUQ7RTIDRVVGLHANCNFSM4HCEPHVA
.

not sure if this where you'd like to talk about potential issues with this specific functionality, but I don't seem to be getting function output in the console even though I can run the functions. if nothing big jumps out at you i can debug more, but it seems to be related to this.

You're saying that function output from the branch you deploy this way is
not showing in the UI, Raj? That is likely related and not sure it's
intended to work, but I know who to ask once you can confirm (and if
possible give me the function name and the site's API ID from the settings
page to track it down internally to confirm, since I have no functions
deployable via CLI right now to test with..)

On Wed, Jun 10, 2020 at 6:00 AM Raj Nigam notifications@github.com wrote:

not sure if this where you'd like to talk about potential issues with this
specific functionality, but I don't seem to be getting function output in
the console even though I can run the functions. if nothing big jumps out
at you i can debug more, but it seems to be related to this.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/netlify/cli/issues/275#issuecomment-641990290, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AABX5IAQ5TJ2CFBLTPBNKBDRV57XLANCNFSM4HCEPHVA
.

When will alias be deployed to npm ? https://github.com/netlify/actions/issues/32

@Sceat netlify-cli/2.54.0 has been published recently that includes --alias flag for netlify deploy command.

Was this page helpful?
0 / 5 - 0 ratings