diff --git a/src/commands/deploy/deploy.ts b/src/commands/deploy/deploy.ts index 6d845206f79..742f7f198fe 100644 --- a/src/commands/deploy/deploy.ts +++ b/src/commands/deploy/deploy.ts @@ -585,7 +585,7 @@ const runDeploy = async ({ draft, branch: alias, include_upload_url: options.uploadSourceZip, - deploy_source: 'cli', + deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli', } const createDeployResponse = await api.createSiteDeploy({ siteId, title, body: createDeployBody }) @@ -1363,7 +1363,12 @@ export const deploy = async (options: DeployOptionValues, command: BaseCommand) } const draft = options.draft || (!deployToProduction && !alias) - const createDeployBody = { draft, branch: alias, include_upload_url: options.uploadSourceZip, deploy_source: 'cli' } + const createDeployBody = { + draft, + branch: alias, + include_upload_url: options.uploadSourceZip, + deploy_source: process.env.NETLIFY_DEPLOY_SOURCE || 'cli', + } // TODO: Type this properly in `@netlify/api`. const deployMetadata = (await api.createSiteDeploy({ diff --git a/tests/integration/commands/deploy/deploy.test.ts b/tests/integration/commands/deploy/deploy.test.ts index dab1038b5eb..d14d7139f43 100644 --- a/tests/integration/commands/deploy/deploy.test.ts +++ b/tests/integration/commands/deploy/deploy.test.ts @@ -1507,6 +1507,34 @@ describe.concurrent('deploy command', () => { }) }) + test('should honor NETLIFY_DEPLOY_SOURCE env var in create deploy request', async (t) => { + await withMockDeploy(async (mockApi) => { + await withSiteBuilder(t, async (builder) => { + builder.withContentFile({ + path: 'public/index.html', + content: '

test

', + }) + + await builder.build() + + await callCli( + ['deploy', '--json', '--no-build', '--dir', 'public'], + getCLIOptions({ + apiUrl: mockApi.apiUrl, + builder, + env: { NETLIFY_DEPLOY_SOURCE: 'agent_runner' }, + }), + ).then(parseDeploy) + + const createDeployRequest = mockApi.requests.find( + (req) => req.method === 'POST' && req.path === '/api/v1/sites/site_id/deploys', + ) + expect(createDeployRequest).toBeDefined() + expect((createDeployRequest!.body as Record).deploy_source).toBe('agent_runner') + }) + }) + }) + test('should include build_version in deploy body', async (t) => { await withMockDeploy(async (mockApi, deployState) => { await withSiteBuilder(t, async (builder) => {