You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there an existing issue that is already proposing this?
I have searched the existing issues
Is your feature request related to a problem? Please describe it
Given a complex configuration with some custom generated jobs with specific step like this one:
import*asCircleCIfrom"@circleci/circleci-config-sdk";// Componentsconstconfig=newCircleCI.Config();constdockerExec=newCircleCI.executors.DockerExecutor("cimg/base:stable");constworkflow=newCircleCI.Workflow("main");// Define "reusable" job, with native JStypecustomJobParameters={name: string;cluster: string;container_name: string;task_role: string;};constcreateCustomJob=(parameters: customJobParameters)=>{conststepsToRun=[newCircleCI.commands.Checkout(),newCircleCI.commands.Run({command: "echo 'Hello World'"}),];// Add deploy step if tag// https://circleci.com/docs/variables/if(process.env.CIRCLE_TAG){stepsToRun.push(newCircleCI.commands.Run({command: "echo 'Deploying'"}));}returnnewCircleCI.Job(parameters.name,dockerExec,stepsToRun);};constjobDefinitions: customJobParameters[]=[{name: "job1",cluster: "cluster",container_name: "container_name",task_role: "task_role",},{name: "job2",cluster: "cluster",container_name: "container_name",task_role: "task_role",},];// Add jobs to workflowjobDefinitions.forEach((jobDefinition)=>{workflow.addJob(createCustomJob(jobDefinition));});config.addWorkflow(workflow);// Print configconsole.log(config.stringify());
I want to add a Step that can only be generated asynchronously. For example I want to send a slack notification that contains the git author. Something like:
constslackCommand=async()=>{constauthor=awaitgetAuthor()// async function with some git callsreturnnewCircleCI.reusable.ReusedCommand(orbSlack.commands['notify'],{name: 'notify-author',event: 'fail',custom: JSON.stringify({text: `Commit by ${author}`,}),})}
For now, I have to make all the function call chain, asynchronous:
import*asCircleCIfrom'@circleci/circleci-config-sdk'// Componentsconstconfig=newCircleCI.Config()constdockerExec=newCircleCI.executors.DockerExecutor('cimg/base:stable')constworkflow=newCircleCI.Workflow('main')// Asynchronous stepconstcreateSlackCommand=async()=>{constauthor=awaitgetAuthor()// async function with some git callsreturnnewCircleCI.reusable.ReusedCommand(orbSlack.commands['notify'],{name: 'notify-author',event: 'fail',custom: JSON.stringify({text: `Commit by ${author}`,}),})}// Define "reusable" job, with native JStypecustomJobParameters={name: stringcluster: stringcontainer_name: stringtask_role: string}constcreateCustomJob=async(parameters: customJobParameters)=>{constslackCmd=awaitcreateSlackCommand()conststepsToRun=[newCircleCI.commands.Checkout(),newCircleCI.commands.Run({command: "echo 'Hello World'"}),slackCmd,]// Add deploy step if tag// https://circleci.com/docs/variables/if(process.env.CIRCLE_TAG){stepsToRun.push(newCircleCI.commands.Run({command: "echo 'Deploying'"}))}returnnewCircleCI.Job(parameters.name,dockerExec,stepsToRun)}constjobDefinitions: customJobParameters[]=[{name: 'job1',cluster: 'cluster',container_name: 'container_name',task_role: 'task_role',},{name: 'job2',cluster: 'cluster',container_name: 'container_name',task_role: 'task_role',},]// Add jobs to workflowasyncfunctionmain(){jobDefinitions.forEach(asyncjobDefinition=>{workflow.addJob(awaitcreateCustomJob(jobDefinition))})config.addWorkflow(workflow)// Print configconsole.log(config.stringify())}main().catch(console.error)
Describe the solution you'd like
It would be awesome if steps array in Job constructor, accepts an array of Command OR async function that returns a Command.
It could lead to make this possible:
import*asCircleCIfrom'@circleci/circleci-config-sdk'// Componentsconstconfig=newCircleCI.Config()constdockerExec=newCircleCI.executors.DockerExecutor('cimg/base:stable')constworkflow=newCircleCI.Workflow('main')// Asynchronous stepconstcreateSlackCommand=async()=>{constauthor=awaitgetAuthor()// async function with some git callsreturnnewCircleCI.reusable.ReusedCommand(orbSlack.commands['notify'],{name: 'notify-author',event: 'fail',custom: JSON.stringify({text: `Commit by ${author}`,}),})}// Define "reusable" job, with native JStypecustomJobParameters={name: stringcluster: stringcontainer_name: stringtask_role: string}constcreateCustomJob=(parameters: customJobParameters)=>{constslackCmd=createSlackCommand()conststepsToRun=[newCircleCI.commands.Checkout(),newCircleCI.commands.Run({command: "echo 'Hello World'"}),createSlackCommand,]// Add deploy step if tag// https://circleci.com/docs/variables/if(process.env.CIRCLE_TAG){stepsToRun.push(newCircleCI.commands.Run({command: "echo 'Deploying'"}))}returnnewCircleCI.Job(parameters.name,dockerExec,stepsToRun)}constjobDefinitions: customJobParameters[]=[{name: 'job1',cluster: 'cluster',container_name: 'container_name',task_role: 'task_role',},{name: 'job2',cluster: 'cluster',container_name: 'container_name',task_role: 'task_role',},]// Add jobs to workflowjobDefinitions.forEach(jobDefinition=>{workflow.addJob(createCustomJob(jobDefinition))})config.addWorkflow(workflow)// Print configconsole.log(config.stringify())
It would be very convenient to do the same with jobs array parameter for Workflow constructor.
Makes sense! And should be doable! I think it will make the final compilation done in stringify likely an async function (major/breaking change) but it makes sense.
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
Given a complex configuration with some custom generated jobs with specific step like this one:
I want to add a Step that can only be generated asynchronously. For example I want to send a slack notification that contains the git author. Something like:
For now, I have to make all the function call chain, asynchronous:
Describe the solution you'd like
It would be awesome if
steps
array inJob
constructor, accepts an array ofCommand
OR async function that returns a Command.It could lead to make this possible:
It would be very convenient to do the same with
jobs
array parameter for Workflow constructor.Teachability, documentation, adoption, migration strategy
Typescript (and maybe example) would be enough to document it
What is the motivation / use case for changing the behavior?
With more powerful primitive for async job/command generation, it will help users to use more js mechanism instead of 2.1 yaml.
The text was updated successfully, but these errors were encountered: