本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
將工作流程元件新增至藍圖
Amazon CodeCatalyst 專案會使用工作流程根據觸發器執行動作。您可以使用工作流程元件來建置和組合工作流程 YAML 檔案。如需詳細資訊,請參閱 工作流程YAML定義。
若要匯入 Amazon CodeCatalyst 藍圖工作流程元件
在您的blueprint.ts
檔案中,新增下列內容:
import { WorkflowBuilder, Workflow } from '@amazon-codecatalyst/codecatalyst-workflows'
工作流程元件範
WorkflowBuilder 元件
您可以使用類別來建立工作流程定義。可將定義指定給工作流程元件,以便在存放庫中轉譯。
import { WorkflowBuilder } from '@amazon-codecatalyst/codecatalyst-workflows' const workflowBuilder = new WorkflowBuilder({} as Blueprint, { Name: 'my_workflow', }); // trigger the workflow on pushes to branch 'main' workflowBuilder.addBranchTrigger(['main']); // add a build action workflowBuilder.addBuildAction({ // give the action a name actionName: 'build_and_do_some_other_stuff', // the action pulls from source code input: { Sources: ['WorkflowSource'], }, // the output attempts to autodiscover test reports, but not in the node modules output: { AutoDiscoverReports: { Enabled: true, ReportNamePrefix: AutoDiscovered, IncludePaths: ['**/*'], ExcludePaths: ['*/node_modules/**/*'], }, }, // execute some arbitrary steps steps: [ 'npm install', 'npm run myscript', 'echo hello-world', ], // add an account connection to the workflow environment: convertToWorkflowEnvironment(myEnv), });
工作流程程序元件
下列範例顯示如何使用 Projen 元件將工作流程 YAML 寫入儲存庫:
import { Workflow } from '@amazon-codecatalyst/codecatalyst-workflows' ... const repo = new SourceRepository const blueprint = this; const workflowDef = workflowBuilder.getDefinition() // creates a workflow.yaml at .aws/workflows/${workflowDef.name}.yaml new Workflow(blueprint, repo, workflowDef); // can also pass in any object and have it rendered as a yaml. This is unsafe and may not produce a valid workflow new Workflow(blueprint, repo, {... some object ...});
連線至環境
許多工作流程都需要在 AWS 帳戶連線中執行。工作流程透過允許動作連接至具有帳戶和角色名稱規格的環境來處理此問題。
import { convertToWorkflowEnvironment } from '@amazon-codecatalyst/codecatalyst-workflows' const myEnv = new Environment(...); // can be passed into a workflow constructor const workflowEnvironment = convertToWorkflowEnvironment(myEnv); // add a build action workflowBuilder.addBuildAction({ ... // add an account connection to the workflow environment: convertToWorkflowEnvironment(myEnv), });