build
build copied to clipboard
How does plugin get deployed url in postDeploy hook?
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?
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?
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
}
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?
I did not see SITE environment variable until I have set it myself for deploy
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
@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
how does one access build.publish folder? Also, the plugin would need to
serve the pages (statically) by itself before testing, right?
On Fri, Oct 11, 2019 at 12:43 PM David Wells [email protected] wrote:
@bahmutov https://github.com/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
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/netlify/build/issues/270?email_source=notifications&email_token=AAQ4BJU5W46Z5DEMXD6CS5TQOCUL3A5CNFSM4I7ZPZQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBAR4YI#issuecomment-541138529, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ4BJV5JLL3OJMFHW4SCY3QOCUL3ANCNFSM4I7ZPZQQ .
-- Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov [email protected] @bahmutov https://twitter.com/@bahmutov https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov
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
super, will change the plugin so it could test both postBuild and postDeploy
On Fri, Oct 11, 2019 at 12:53 PM David Wells [email protected] wrote:
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
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/netlify/build/issues/270?email_source=notifications&email_token=AAQ4BJQ2X2ZMIOQGDEDEH5DQOCVRBA5CNFSM4I7ZPZQ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBASXGY#issuecomment-541141915, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQ4BJTQ5KIVBSOOXLF5WQDQOCVRBANCNFSM4I7ZPZQQ .
-- Dr. Gleb Bahmutov, PhD
Schedule video chat / phone call / meeting with me via https://calendly.com/bahmutov [email protected] @bahmutov https://twitter.com/@bahmutov https://glebbahmutov.com/ https://glebbahmutov.com/blog https://github.com/bahmutov
Whats the status on this?
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! :)
Any update here? Getting the site URL would unlock some interesting workflows.
@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.
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.
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!
This issue was closed because it had no activity for over 1 year.