From 820a6a0d9b7c3b38202e317bde24d9378ad77341 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:13:27 -0800 Subject: [PATCH 1/6] Fixing build script url option --- src/commands/hld/pipeline.ts | 2 +- src/commands/project/pipeline.ts | 2 +- src/commands/service/pipeline.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/hld/pipeline.ts b/src/commands/hld/pipeline.ts index c4aada89b..adf13b7d5 100644 --- a/src/commands/hld/pipeline.ts +++ b/src/commands/hld/pipeline.ts @@ -39,7 +39,7 @@ export const installHldToManifestPipelineDecorator = ( .option("-m, --manifest-url ", "Manifest Repository URL") .option("-d, --devops-project ", "Azure DevOps Project") .option( - "-b, --build-script ", + "-b, --build-script-url ", `Build Script URL. By default it is '${BUILD_SCRIPT_URL}'.` ) .action(async opts => { diff --git a/src/commands/project/pipeline.ts b/src/commands/project/pipeline.ts index 19e5c470d..a14a231ad 100644 --- a/src/commands/project/pipeline.ts +++ b/src/commands/project/pipeline.ts @@ -40,7 +40,7 @@ export const deployLifecyclePipelineCommandDecorator = ( .option("-e, --hld-url ", "HLD Repository URL") .option("-d, --devops-project ", "Azure DevOps Project") .option( - "-b, --build-script ", + "-b, --build-script-url ", `Build Script URL. By default it is '${BUILD_SCRIPT_URL}'.` ) .action(async opts => { diff --git a/src/commands/service/pipeline.ts b/src/commands/service/pipeline.ts index 3079baa43..ebeca93ba 100644 --- a/src/commands/service/pipeline.ts +++ b/src/commands/service/pipeline.ts @@ -42,7 +42,7 @@ export const installBuildPipelineCommandDecorator = ( .option("-u, --repo-url ", "Repository URL") .option("-d, --devops-project ", "Azure DevOps Project") .option( - "-b, --build-script ", + "-b, --build-script-url ", `Build Script URL. By default it is '${BUILD_SCRIPT_URL}'.` ) .option( @@ -106,7 +106,7 @@ export const installBuildPipelineCommandDecorator = ( } if (typeof buildScriptUrl !== "string") { throw new Error( - `--build-script must be of type 'string', ${typeof buildScriptUrl} given.` + `--build-script-url must be of type 'string', ${typeof buildScriptUrl} given.` ); } } catch (err) { From af80287f10ccd76dfb3971e3dcfd3e0330a15c7b Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:17:51 -0800 Subject: [PATCH 2/6] docs --- docs/hld-management.md | 2 +- docs/project-management.md | 2 +- docs/service-management.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/hld-management.md b/docs/hld-management.md index c1d3c893c..86b4af6df 100644 --- a/docs/hld-management.md +++ b/docs/hld-management.md @@ -89,7 +89,7 @@ Options: -u, --hld-url HLD Repository URL -m, --manifest-url Manifest Repository URL -d, --devops-project Azure DevOps Project - -b, --build-script Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. + -b, --build-script-url Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. -h, --help output usage information ``` diff --git a/docs/project-management.md b/docs/project-management.md index 708fb63cd..3793474dd 100644 --- a/docs/project-management.md +++ b/docs/project-management.md @@ -118,6 +118,6 @@ Options: -u, --repo-url Repository URL -e, --hld-url HLD Repository URL -d, --devops-project Azure DevOps Project - -b, --build-script Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. + -b, --build-script-url Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. -h, --help output usage information ``` diff --git a/docs/service-management.md b/docs/service-management.md index 5d30fe424..5ba7ce939 100644 --- a/docs/service-management.md +++ b/docs/service-management.md @@ -77,7 +77,7 @@ Options: -r, --repo-name Repository Name in Azure DevOps -u, --repo-url Repository URL -d, --devops-project Azure DevOps Project - -b, --build-script Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. + -b, --build-script-url Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. -l, --packages-dir The mono-repository directory containing this service definition. ie. '--packages-dir packages' if my-service is located under ./packages/my-service. Omitting this option implies this is a not a mono-repository. -h, --help output usage information ``` From 17455c6f0c94c09bfd2cffe5c2c142a878da2784 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:35:27 -0800 Subject: [PATCH 3/6] Adding Build scripts back to project install pipelines --- docs/project-management.md | 1 - src/commands/project/pipeline.test.ts | 8 +---- src/commands/project/pipeline.ts | 42 +++++++++++++++++---------- tests/validations.sh | 2 +- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/docs/project-management.md b/docs/project-management.md index 3793474dd..16c835671 100644 --- a/docs/project-management.md +++ b/docs/project-management.md @@ -116,7 +116,6 @@ Options: -o, --org-name Organization Name for Azure DevOps -r, --repo-name Repository Name in Azure DevOps -u, --repo-url Repository URL - -e, --hld-url HLD Repository URL -d, --devops-project Azure DevOps Project -b, --build-script-url Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'. -h, --help output usage information diff --git a/src/commands/project/pipeline.test.ts b/src/commands/project/pipeline.test.ts index cf1722cd9..f3373d392 100644 --- a/src/commands/project/pipeline.test.ts +++ b/src/commands/project/pipeline.test.ts @@ -24,8 +24,7 @@ describe("validate pipeline config", () => { "testDevopsProject", "testPipeline", "repoName", - "https:/repoulr", - "https://hldurl", + "https://repourl", "https://buildscript", "af8e99c1234ef93e8c4365b1dc9bd8d9ba987d3" ]; @@ -57,7 +56,6 @@ describe("create hld to manifest pipeline test", () => { "pipelineName", "repoName", "repoUrl", - "hldRepoUrl", "azDoProject", "buildScriptUrl", exitFn @@ -76,7 +74,6 @@ describe("create hld to manifest pipeline test", () => { "pipelineName", "repoName", "repoUrl", - "hldRepoUrl", "azDoProject", "buildScriptUrl", exitFn @@ -98,7 +95,6 @@ describe("create hld to manifest pipeline test", () => { "pipelineName", "repoName", "repoUrl", - "hldRepoUrl", "azDoProject", "buildScriptUrl", exitFn @@ -119,7 +115,6 @@ describe("create hld to manifest pipeline test", () => { "pipelineName", "repoName", "repoUrl", - "hldRepoUrl", "azDoProject", "buildScriptUrl", exitFn @@ -145,7 +140,6 @@ describe("create hld to manifest pipeline test", () => { "pipelineName", "repoName", "repoUrl", - "hldRepoUrl", "azDoProject", "buildScriptUrl", exitFn diff --git a/src/commands/project/pipeline.ts b/src/commands/project/pipeline.ts index a14a231ad..61a93f8e1 100644 --- a/src/commands/project/pipeline.ts +++ b/src/commands/project/pipeline.ts @@ -1,5 +1,8 @@ import { IBuildApi } from "azure-devops-node-api/BuildApi"; -import { BuildDefinition } from "azure-devops-node-api/interfaces/BuildInterfaces"; +import { + BuildDefinition, + BuildDefinitionVariable +} from "azure-devops-node-api/interfaces/BuildInterfaces"; import commander from "commander"; import { Config } from "../../config"; import { BUILD_SCRIPT_URL } from "../../lib/constants"; @@ -37,7 +40,6 @@ export const deployLifecyclePipelineCommandDecorator = ( .option("-o, --org-name ", "Organization Name for Azure DevOps") .option("-r, --repo-name ", "Repository Name in Azure DevOps") .option("-u, --repo-url ", "Repository URL") - .option("-e, --hld-url ", "HLD Repository URL") .option("-d, --devops-project ", "Azure DevOps Project") .option( "-b, --build-script-url ", @@ -64,7 +66,6 @@ export const deployLifecyclePipelineCommandDecorator = ( pipelineName = getRepositoryName(gitOriginUrl) + "-lifecycle", repoName = getRepositoryName(gitOriginUrl), repoUrl = getRepositoryUrl(gitOriginUrl), - hldUrl = azure_devops && azure_devops.hld_repository, buildScriptUrl = BUILD_SCRIPT_URL } = opts; @@ -73,9 +74,8 @@ export const deployLifecyclePipelineCommandDecorator = ( orgName, devopsProject, pipelineName, + repoName, repoUrl, - hldUrl, - hldUrl, buildScriptUrl, personalAccessToken ) @@ -90,7 +90,6 @@ export const deployLifecyclePipelineCommandDecorator = ( pipelineName, repoName, repoUrl, - hldUrl, devopsProject, buildScriptUrl, process.exit @@ -113,7 +112,6 @@ export const deployLifecyclePipelineCommandDecorator = ( * @param pipelineName Name of this build pipeline in AzDo * @param repoName Name of repo * @param repoUrl Repo URL - * @param hldUrl URL of the HLD * @param buildScriptUrl Build Script URL * @param personalAccessToken Personal Access token with access to the HLD repository and materialized manifest repository. */ @@ -123,7 +121,6 @@ export const isValidConfig = ( pipelineName: any, repoName: any, repoUrl: any, - hldUrl: any, buildScriptUrl: any, personalAccessToken: any ): boolean => { @@ -134,7 +131,6 @@ export const isValidConfig = ( logger.debug(`pipelineName: ${pipelineName}`); logger.debug(`repoName: ${repoName}`); logger.debug(`repoUrl: ${repoUrl}`); - logger.debug(`hldUrl: ${hldUrl}`); logger.debug(`devopsProject: ${devopsProject}`); logger.debug(`buildScriptUrl: ${buildScriptUrl}`); @@ -163,11 +159,6 @@ export const isValidConfig = ( `--repo-url must be of type 'string', ${typeof repoUrl} given.` ); } - if (typeof hldUrl !== "string") { - missingConfig.push( - `--hld-url must be of type 'string', ${typeof hldUrl} given.` - ); - } if (typeof devopsProject !== "string") { missingConfig.push( `--devops-project must be of type 'string', ${typeof devopsProject} given.` @@ -195,7 +186,6 @@ export const isValidConfig = ( * @param pipelineName * @param repositoryName * @param repositoryUrl - * @param hldRepoUrl * @param project * @param buildScriptUrl Build Script URL * @param exitFn @@ -206,7 +196,6 @@ export const installLifecyclePipeline = async ( pipelineName: string, repositoryName: string, repositoryUrl: string, - hldRepoUrl: string, project: string, buildScriptUrl: string, exitFn: (status: number) => void @@ -229,6 +218,7 @@ export const installLifecyclePipeline = async ( pipelineName, repositoryName, repositoryUrl, + variables: requiredPipelineVariables(buildScriptUrl), yamlFileBranch: "master", yamlFilePath: "hld-lifecycle.yaml" }); @@ -267,3 +257,23 @@ export const installLifecyclePipeline = async ( return exitFn(1); } }; + +/** + * Builds and returns variables required for the lifecycle pipeline. + * @param accessToken Access token with access to the HLD repository. + * @param buildScriptUrl Build Script URL + * @param hldRepoUrl to the HLD repository. + * @returns Object containing the necessary run-time variables for the lifecycle pipeline. + */ + +export const requiredPipelineVariables = ( + buildScriptUrl: string +): { [key: string]: BuildDefinitionVariable } => { + return { + BUILD_SCRIPT_URL: { + allowOverride: true, + isSecret: false, + value: buildScriptUrl + } + }; +}; diff --git a/tests/validations.sh b/tests/validations.sh index 60c06b049..4bb2f6f76 100644 --- a/tests/validations.sh +++ b/tests/validations.sh @@ -191,7 +191,7 @@ lifecycle_pipeline_name="$mono_repo_dir-lifecycle" pipeline_exists $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name # Deploy lifecycle pipeline and verify it runs. -spk project install-lifecycle-pipeline --org-name $AZDO_ORG --devops-project $AZDO_PROJECT --hld-url $hld_repo_url --repo-url $repo_url --repo-name $mono_repo_dir --pipeline-name $lifecycle_pipeline_name --personal-access-token $ACCESS_TOKEN_SECRET >> $TEST_WORKSPACE/log.txt +spk project install-lifecycle-pipeline --org-name $AZDO_ORG --devops-project $AZDO_PROJECT --repo-url $repo_url --repo-name $mono_repo_dir --pipeline-name $lifecycle_pipeline_name --personal-access-token $ACCESS_TOKEN_SECRET >> $TEST_WORKSPACE/log.txt # TODO: Verify the lifecycle pipeline sucessfully runs # Verify lifecycle pipeline was created From 027125fdd813a216ec405913e6a10ba9dd741b0a Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:37:30 -0800 Subject: [PATCH 4/6] docs --- src/commands/project/pipeline.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/commands/project/pipeline.ts b/src/commands/project/pipeline.ts index 61a93f8e1..9c5245345 100644 --- a/src/commands/project/pipeline.ts +++ b/src/commands/project/pipeline.ts @@ -260,9 +260,7 @@ export const installLifecyclePipeline = async ( /** * Builds and returns variables required for the lifecycle pipeline. - * @param accessToken Access token with access to the HLD repository. * @param buildScriptUrl Build Script URL - * @param hldRepoUrl to the HLD repository. * @returns Object containing the necessary run-time variables for the lifecycle pipeline. */ From ebb978e248aa3e152d47e61aa0b95662f0d28155 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:48:22 -0800 Subject: [PATCH 5/6] Actually hooking in isValidConfig for service pipeline --- src/commands/service/pipeline.ts | 59 ++++++-------------------------- 1 file changed, 11 insertions(+), 48 deletions(-) diff --git a/src/commands/service/pipeline.ts b/src/commands/service/pipeline.ts index ebeca93ba..790ca8726 100644 --- a/src/commands/service/pipeline.ts +++ b/src/commands/service/pipeline.ts @@ -64,54 +64,17 @@ export const installBuildPipelineCommandDecorator = ( buildScriptUrl = BUILD_SCRIPT_URL } = opts; - logger.debug(`orgName: ${orgName}`); - logger.debug(`personalAccessToken: XXXXXXXXXXXXXXXXX`); - logger.debug(`devopsProject: ${devopsProject}`); - logger.debug(`pipelineName: ${pipelineName}`); - logger.debug(`packagesDir: ${packagesDir}`); - logger.debug(`repoName: ${repoName}`); - logger.debug(`repoUrl: ${repoUrl}`); - logger.debug(`buildScriptUrl: ${buildScriptUrl}`); - - try { - if (typeof pipelineName !== "string") { - throw new Error( - `--pipeline-name must be of type 'string', ${typeof pipelineName} given.` - ); - } - if (typeof personalAccessToken !== "string") { - throw new Error( - `--personal-access-token must be of type 'string', ${typeof personalAccessToken} given.` - ); - } - if (typeof orgName !== "string") { - throw new Error( - `--org-url must be of type 'string', ${typeof orgName} given.` - ); - } - if (typeof repoName !== "string") { - throw new Error( - `--repo-name must be of type 'string', ${typeof repoName} given.` - ); - } - if (typeof repoUrl !== "string") { - throw new Error( - `--repo-url must be of type 'string', ${typeof repoUrl} given.` - ); - } - if (typeof devopsProject !== "string") { - throw new Error( - `--devops-project must be of type 'string', ${typeof devopsProject} given.` - ); - } - if (typeof buildScriptUrl !== "string") { - throw new Error( - `--build-script-url must be of type 'string', ${typeof buildScriptUrl} given.` - ); - } - } catch (err) { - logger.error(`Error occurred validating inputs for ${serviceName}`); - logger.error(err); + if ( + !isValidConfig( + orgName, + devopsProject, + pipelineName, + repoName, + repoUrl, + buildScriptUrl, + personalAccessToken + ) + ) { process.exit(1); } From 2e9cd9ec0cc5b68fa576e3af9c7f3f707be4e4a4 Mon Sep 17 00:00:00 2001 From: Michael Tarng <20913254+mtarng@users.noreply.github.com> Date: Thu, 23 Jan 2020 14:50:31 -0800 Subject: [PATCH 6/6] adding -url --- src/commands/project/pipeline.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/project/pipeline.ts b/src/commands/project/pipeline.ts index 9c5245345..b6dd94d93 100644 --- a/src/commands/project/pipeline.ts +++ b/src/commands/project/pipeline.ts @@ -166,7 +166,7 @@ export const isValidConfig = ( } if (typeof buildScriptUrl !== "string") { missingConfig.push( - `--build-script must be of type 'string', ${typeof buildScriptUrl} given.` + `--build-script-url must be of type 'string', ${typeof buildScriptUrl} given.` ); }