sszczep
sszczep
CDCloudflare Developers
Created by sszczep on 12/9/2023 in #pages-help
Deploying Pages using Wrangler - returning deployment URL
Hey, I'm currently working on CI/CD pipeline. I've created the following script based on Cloudflare's GitHub Action:
await exec.exec(`npx wrangler pages deploy "build" --project-name="${process.env.CLOUDFLARE_PROJECT_NAME}" --branch="${branch}" --commit-hash="${commitHash}" --commit-message="${commitMessage}"`);

const requestUrl = `https://api.cloudflare.com/client/v4/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}/pages/projects/${process.env.CLOUDFLARE_PROJECT_NAME}`;
const response = await fetch(requestUrl, {
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}` },
});

const { result } = await response.json();

return result.latest_deployment.url;
await exec.exec(`npx wrangler pages deploy "build" --project-name="${process.env.CLOUDFLARE_PROJECT_NAME}" --branch="${branch}" --commit-hash="${commitHash}" --commit-message="${commitMessage}"`);

const requestUrl = `https://api.cloudflare.com/client/v4/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}/pages/projects/${process.env.CLOUDFLARE_PROJECT_NAME}`;
const response = await fetch(requestUrl, {
headers: { Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}` },
});

const { result } = await response.json();

return result.latest_deployment.url;
Unfortunately it does not support concurrent deployments (it only fetches the latest deployment url). Is there a valid way of extracting the URL from wrangler output which would not break with future releases?
2 replies