Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Deploy Context / Branch from CLI #275

Closed
githubjosh opened this issue Mar 28, 2019 · 40 comments · Fixed by #907 or #943
Closed

Set Deploy Context / Branch from CLI #275

githubjosh opened this issue Mar 28, 2019 · 40 comments · Fixed by #907 or #943
Assignees
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@githubjosh
Copy link

githubjosh commented Mar 28, 2019

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.

@bcomnes
Copy link
Contributor

bcomnes commented Mar 28, 2019

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

@swyxio
Copy link
Contributor

swyxio commented Mar 29, 2019

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.

@kirillgroshkov
Copy link

kirillgroshkov commented Apr 1, 2019

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.

@kirillgroshkov
Copy link

Related: #44

@HamidAghdaee
Copy link

Very much would appreciate this functionality as well.

@thundernixon
Copy link

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!

@swyxio
Copy link
Contributor

swyxio commented Jun 5, 2019

acknowledged the importance of this.

@MeixnerTobias
Copy link

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.

@fool
Copy link
Contributor

fool commented Jun 18, 2019

should inform customers in addition to this thread:

@TjeuKayim
Copy link

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

@kalinchernev
Copy link

Got the latest version of the CLI

USAGE
  $ 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

@noraj
Copy link

noraj commented Dec 21, 2019

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.

@csvn
Copy link

csvn commented Mar 31, 2020

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.

@RaeesBhatti
Copy link
Contributor

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

@jamietanna
Copy link

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

@RaeesBhatti
Copy link
Contributor

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.

@phaseOne
Copy link

@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.

@chaudharykiran
Copy link

Any update on this issue.

@austinh
Copy link

austinh commented Apr 29, 2020

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.

@Sceat
Copy link

Sceat commented Apr 29, 2020

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

@RaeesBhatti RaeesBhatti changed the title Set Deploy Context from CLI Set Deploy Context / Branch from CLI May 8, 2020
@RaeesBhatti RaeesBhatti self-assigned this May 15, 2020
@RaeesBhatti RaeesBhatti added the type: feature code contributing to the implementation of a feature and/or user facing functionality label May 15, 2020
@jamietanna
Copy link

Thank you 🎉

@RaeesBhatti
Copy link
Contributor

netlify-cli@2.53.0 has just been released with support for branch specific deploys. Please update and try it out with netlify deploy -b test

@phaseOne
Copy link

phaseOne commented Jun 3, 2020

Thanks for the other PR as well! netlify/js-client#105

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

@rajington
Copy link

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?

@RaeesBhatti
Copy link
Contributor

@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

@Sceat
Copy link

Sceat commented Jun 4, 2020

seems we can't yet link a domain ?

image

@rajington
Copy link

rajington commented Jun 4, 2020

@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.

@RaeesBhatti
Copy link
Contributor

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?

@rajington
Copy link

The author is considering the same thing for the GitHub Action! nwtgck/actions-netlify#178 (comment)

@malcolm-kee
Copy link

malcolm-kee commented Jun 7, 2020

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?

@fool
Copy link
Contributor

fool commented Jun 8, 2020 via email

@Sceat
Copy link

Sceat commented Jun 8, 2020

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

@fool
Copy link
Contributor

fool commented Jun 8, 2020 via email

@rajington
Copy link

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.

@fool
Copy link
Contributor

fool commented Jun 11, 2020 via email

@Sceat
Copy link

Sceat commented Jun 12, 2020

When will alias be deployed to npm ? netlify/actions#32

@RaeesBhatti
Copy link
Contributor

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

@alexjfno1
Copy link

@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

@RaeesBhatti is there any update on getting --trigger to work with --alias? I'd like to trigger a build & deploy of a specific branch without having to upload assets (Netlify handles building and testing for us).

@erezrokah
Copy link
Contributor

Hi @alexjfno1, I opened a new issue #1572 to track this as it will require some API changes.

@alexjfno1
Copy link

Thanks @erezrokah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.