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

How does plugin get deployed url in postDeploy hook? #270

Closed
bahmutov opened this issue Oct 11, 2019 · 16 comments
Closed

How does plugin get deployed url in postDeploy hook? #270

bahmutov opened this issue Oct 11, 2019 · 16 comments
Labels
enhancement New feature or request question Further information is requested stale

Comments

@bahmutov
Copy link

Imagine you are writing a postDeploy hook - like Lighthouse or Cypress need to test the deployed site. How would the plugin get the deployed unique url to test?

@ehmicky
Copy link
Contributor

ehmicky commented Oct 11, 2019

Hi @bahmutov,

At the moment, we are using the SITE environment variable. Our current plugins allow usually allow users to override it with plugin.config.site (see example).

@DavidWells Could you confirm I got this right?

I actually think we should expose this to plugin methods as constants.site. What do you think @DavidWells and @bahmutov?

@ehmicky ehmicky added the question Further information is requested label Oct 11, 2019
@bahmutov
Copy link
Author

So the user would manually set SITE environment variable (I see the Lighthouse plugin uses this for example)? I could read it, but to me this would not work with unique preview deploys, I would rather not worry about that and instead pass the deployed url to the plugin inside the argument object.

postDeploy: async (opts) {
  // unique deploy url in opts
  const url = opts.site || process.env.SITE
}

@ehmicky
Copy link
Contributor

ehmicky commented Oct 11, 2019

I think the SITE environment variable is setup by our BuildBot alongside other environment variables which might help you as well. The BuildBot is the environment in which netlify/build is running.

I might be wrong though: @DavidWells is this correct?

@bahmutov
Copy link
Author

I did not see SITE environment variable until I have set it myself for deploy

@bahmutov
Copy link
Author

I have tried using URL env variables like this

const baseUrl = process.env.DEPLOY_URL || process.env.DEPLOY_PRIME_URL || process.env.URL

but for example for this run https://app.netlify.com/sites/condescending-knuth-7cff53/deploys/5da0af7510b65eacdab96a44 the passed first url is 404

cypressPlugin start against https://5da0af7510b65eacdab96a44--condescending-knuth-7cff53.netlify.com
12:38:34 PM:      CypressError: cy.visit() failed trying to load:
12:38:34 PM: https://5da0af7510b65eacdab96a44--condescending-knuth-7cff53.netlify.com/
12:38:34 PM: The response we received from your web server was:
12:38:34 PM:   > 404: Not Found

@DavidWells
Copy link
Contributor

@bahmutov that code is correct.

The issue right now is the deployment is actually happening outside of the lifecycle and the real site is not yet live when your code is called.

We are working on resolving this.

For the time being, the cypress tests would need to run against the locally build files in the build.publish directory

@bahmutov
Copy link
Author

bahmutov commented Oct 11, 2019 via email

@DavidWells
Copy link
Contributor

DavidWells commented Oct 11, 2019

Yeah the site would need to get served with something like https://www.npmjs.com/package/serve

You can get the build directory like so:

module.exports = function netlifyPlugin(pluginConfig) {
  return {
    postBuild: ({ config }) => {
      console.log(config.build.publish)
    },
  }
}

We are working on getting this sorted out so you can run against live URLs without the need to serve locally

@bahmutov
Copy link
Author

bahmutov commented Oct 11, 2019 via email

@ehmicky ehmicky added the enhancement New feature or request label Oct 22, 2019
@Lockoo
Copy link

Lockoo commented Nov 17, 2019

Whats the status on this?

@ehmicky
Copy link
Contributor

ehmicky commented Nov 18, 2019

We have a pending PR at #513 to add the base support for this. Once this is merged, we will need to do some additional work in this repository to make this work. Stay tuned! :)

@mwickett
Copy link

Any update here? Getting the site URL would unlock some interesting workflows.

@ehmicky
Copy link
Contributor

ehmicky commented Apr 24, 2020

@mwickett We are still on the design phase for this feature. It turns out it requires some rather big infrastructure changes so we are evaluating the best way to approach this.

@adamlutz
Copy link

I would be interested in opting in as a beta tester if it's possible for this feature :)
My use case is similar to the above-- I'm hoping to trigger a browserstack e2e test against a live build.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had activity in 1 year. It will be closed in 14 days if no further activity occurs. Thanks!

@github-actions github-actions bot added the stale label Oct 18, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

This issue was closed because it had no activity for over 1 year.

@github-actions github-actions bot closed this as completed Nov 2, 2022
ericapisani pushed a commit that referenced this issue Dec 7, 2022
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested stale
Projects
None yet
Development

No branches or pull requests

6 participants