Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 8dbf51b

Browse files
authored
Adding pipeline variable to specify build.sh url (#156)
* Adding buildScriptUrl for each pipeline as a EnvVar and Pipeline Variable * logic + docs, confirmed working via smoketest, need to fix unit tests * updating unit tests * Adding constants * missed 2...
1 parent b6759c7 commit 8dbf51b

File tree

13 files changed

+274
-114
lines changed

13 files changed

+274
-114
lines changed

docs/hld-management.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ invoke "manifest generation"
7777
and configuration into Kubernetes yaml.
7878

7979
```
80-
Usage: hld install-manifest-pipeline|m [options]
80+
Usage: hld install-manifest-pipeline|p [options]
8181
8282
Install the manifest generation pipeline to your Azure DevOps instance. Default values are set in spk-config.yaml and can be loaded via spk init or overriden via option flags.
8383
@@ -89,6 +89,7 @@ Options:
8989
-u, --hld-url <hld-url> HLD Repository URL
9090
-m, --manifest-url <manifest-url> Manifest Repository URL
9191
-d, --devops-project <devops-project> Azure DevOps Project
92+
-b, --build-script <build-script-url> Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'.
9293
-h, --help output usage information
9394
```
9495

docs/project-management.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ Options:
111111
-u, --repo-url <repo-url> Repository URL
112112
-e, --hld-url <hld-url> HLD Repository URL
113113
-d, --devops-project <devops-project> Azure DevOps Project
114+
-b, --build-script <build-script-url> Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'.
114115
-h, --help output usage information
115116
```

docs/service-management.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ https://docs.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azur
6565
```
6666
Usage: service install-build-pipeline|p [options] <service-name>
6767
68-
Install the build and push to acr pipeline for a service to your Azure DevOps instance.
68+
Install the build and push to acr pipeline for a service to your Azure DevOps instance
6969
7070
Options:
7171
-n, --pipeline-name <pipeline-name> Name of the pipeline to be created
@@ -74,6 +74,7 @@ Options:
7474
-r, --repo-name <repo-name> Repository Name in Azure DevOps
7575
-u, --repo-url <repo-url> Repository URL
7676
-d, --devops-project <devops-project> Azure DevOps Project
77+
-b, --build-script <build-script-url> Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'.
7778
-l, --packages-dir <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.
7879
-h, --help output usage information
7980
```

src/commands/hld/pipeline.test.ts

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@ afterAll(() => {
2222
});
2323

2424
describe("required pipeline variables", () => {
25-
it("should use access token and repo as pipeline vars", () => {
26-
const variables = requiredPipelineVariables("foo", "bar");
25+
it("should use have the proper pipeline vars vars", () => {
26+
const variables = requiredPipelineVariables(
27+
"somePAT",
28+
"buildScriptUrl",
29+
"manifestRepoUrl"
30+
);
31+
32+
expect(Object.keys(variables).length).toBe(3);
2733

28-
expect(Object.keys(variables).length).toBe(2);
29-
expect(variables.PAT.value).toBe("foo");
34+
expect(variables.PAT.value).toBe("somePAT");
3035
expect(variables.PAT.isSecret).toBe(true);
36+
expect(variables.PAT.allowOverride).toBe(true);
37+
38+
expect(variables.BUILD_SCRIPT_URL.value).toBe("buildScriptUrl");
39+
expect(variables.BUILD_SCRIPT_URL.isSecret).toBe(false);
40+
expect(variables.BUILD_SCRIPT_URL.allowOverride).toBe(true);
3141

32-
expect(variables.MANIFEST_REPO.value).toBe("bar");
42+
expect(variables.MANIFEST_REPO.value).toBe("manifestRepoUrl");
3343
expect(variables.MANIFEST_REPO.isSecret).toBe(false);
44+
expect(variables.MANIFEST_REPO.allowOverride).toBe(true);
3445
});
3546
});
3647

@@ -40,13 +51,14 @@ describe("create hld to manifest pipeline test", () => {
4051

4152
const exitFn = jest.fn();
4253
await installHldToManifestPipeline(
43-
"foo",
44-
"bar",
45-
"wow",
46-
"amazing",
47-
"meow",
48-
"baz",
54+
"orgName",
55+
"personalAccessToken",
56+
"hldRepoName",
57+
"hldRepoUrl",
58+
"manifestRepoUrl",
59+
"project",
4960
"pipelineName",
61+
"buildScriptUrl",
5062
exitFn
5163
);
5264

@@ -58,13 +70,14 @@ describe("create hld to manifest pipeline test", () => {
5870

5971
const exitFn = jest.fn();
6072
await installHldToManifestPipeline(
61-
"foo",
62-
"bar",
63-
"baz",
64-
"wow",
65-
"wao",
66-
"baz",
73+
"orgName",
74+
"personalAccessToken",
75+
"hldRepoName",
76+
"hldRepoUrl",
77+
"manifestRepoUrl",
78+
"project",
6779
"pipelineName",
80+
"buildScriptUrl",
6881
exitFn
6982
);
7083

@@ -79,13 +92,14 @@ describe("create hld to manifest pipeline test", () => {
7992

8093
const exitFn = jest.fn();
8194
await installHldToManifestPipeline(
82-
"foo",
83-
"bar",
84-
"baz",
85-
"wow",
86-
"wao",
87-
"baz",
95+
"orgName",
96+
"personalAccessToken",
97+
"hldRepoName",
98+
"hldRepoUrl",
99+
"manifestRepoUrl",
100+
"project",
88101
"pipelineName",
102+
"buildScriptUrl",
89103
exitFn
90104
);
91105

@@ -99,13 +113,14 @@ describe("create hld to manifest pipeline test", () => {
99113

100114
const exitFn = jest.fn();
101115
await installHldToManifestPipeline(
102-
"foo",
103-
"bar",
104-
"baz",
105-
"wow",
106-
"wao",
107-
"baz",
116+
"orgName",
117+
"personalAccessToken",
118+
"hldRepoName",
119+
"hldRepoUrl",
120+
"manifestRepoUrl",
121+
"project",
108122
"pipelineName",
123+
"buildScriptUrl",
109124
exitFn
110125
);
111126

src/commands/hld/pipeline.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from "azure-devops-node-api/interfaces/BuildInterfaces";
66
import commander from "commander";
77
import { Config } from "../../config";
8+
import { BUILD_SCRIPT_URL } from "../../lib/constants";
89
import { getRepositoryName } from "../../lib/gitutils";
910
import {
1011
createPipelineForDefinition,
@@ -20,7 +21,7 @@ export const installHldToManifestPipelineDecorator = (
2021
): void => {
2122
command
2223
.command("install-manifest-pipeline")
23-
.alias("m")
24+
.alias("p")
2425
.description(
2526
"Install the manifest generation pipeline to your Azure DevOps instance. Default values are set in spk-config.yaml and can be loaded via spk init or overriden via option flags."
2627
)
@@ -37,6 +38,10 @@ export const installHldToManifestPipelineDecorator = (
3738
.option("-u, --hld-url <hld-url>", "HLD Repository URL")
3839
.option("-m, --manifest-url <manifest-url>", "Manifest Repository URL")
3940
.option("-d, --devops-project <devops-project>", "Azure DevOps Project")
41+
.option(
42+
"-b, --build-script <build-script-url>",
43+
`Build Script URL. By default it is '${BUILD_SCRIPT_URL}'.`
44+
)
4045
.action(async opts => {
4146
const { azure_devops } = Config();
4247

@@ -52,7 +57,8 @@ export const installHldToManifestPipelineDecorator = (
5257
personalAccessToken = azure_devops && azure_devops.access_token,
5358
devopsProject = azure_devops && azure_devops.project,
5459
hldName = getRepositoryName(hldUrl),
55-
pipelineName = hldName + "-to-" + manifestRepoName
60+
pipelineName = hldName + "-to-" + manifestRepoName,
61+
buildScriptUrl = BUILD_SCRIPT_URL
5662
} = opts;
5763

5864
logger.debug(`orgName: ${orgName}`);
@@ -62,6 +68,7 @@ export const installHldToManifestPipelineDecorator = (
6268
logger.debug(`manifestUrl: ${manifestUrl}`);
6369
logger.debug(`hldName: ${hldName}`);
6470
logger.debug(`hldUrl: ${hldUrl}`);
71+
logger.debug(`buildScriptUrl: ${buildScriptUrl}`);
6572

6673
try {
6774
if (typeof pipelineName !== "string") {
@@ -105,6 +112,11 @@ export const installHldToManifestPipelineDecorator = (
105112
`--devops-project must be of type 'string', ${typeof devopsProject} given.`
106113
);
107114
}
115+
if (typeof buildScriptUrl !== "string") {
116+
throw new Error(
117+
`--build-script must be of type 'string', ${typeof buildScriptUrl} given.`
118+
);
119+
}
108120
} catch (err) {
109121
logger.error(
110122
`Error occurred validating inputs for hld install-manifest-pipeline`
@@ -122,6 +134,7 @@ export const installHldToManifestPipelineDecorator = (
122134
manifestUrl,
123135
devopsProject,
124136
pipelineName,
137+
buildScriptUrl,
125138
process.exit
126139
);
127140
} catch (err) {
@@ -143,6 +156,8 @@ export const installHldToManifestPipelineDecorator = (
143156
* @param hldRepoUrl URL to the HLD repository
144157
* @param manifestRepoUrl URL to the materialized manifest repository
145158
* @param project Azure DevOps project that the HLD and Materialized manifest repository is in
159+
* @param pipelineName Name of this build pipeline in AzDo
160+
* @param buildScriptUrl Build Script URL
146161
*/
147162
export const installHldToManifestPipeline = async (
148163
orgName: string,
@@ -152,6 +167,7 @@ export const installHldToManifestPipeline = async (
152167
manifestRepoUrl: string,
153168
project: string,
154169
pipelineName: string,
170+
buildScriptUrl: string,
155171
exitFn: (status: number) => void
156172
) => {
157173
let devopsClient;
@@ -172,7 +188,11 @@ export const installHldToManifestPipeline = async (
172188
pipelineName: pipelineName,
173189
repositoryName: hldRepoName,
174190
repositoryUrl: hldRepoUrl,
175-
variables: requiredPipelineVariables(personalAccessToken, manifestRepoUrl),
191+
variables: requiredPipelineVariables(
192+
personalAccessToken,
193+
buildScriptUrl,
194+
manifestRepoUrl
195+
),
176196
yamlFileBranch: "master",
177197
yamlFilePath: `manifest-generation.yaml`
178198
} as IAzureRepoPipelineConfig);
@@ -208,14 +228,21 @@ export const installHldToManifestPipeline = async (
208228
/**
209229
* Builds and returns variables required for the HLD to Manifest pipeline.
210230
* @param accessToken Access token with access to the manifest repository.
231+
* @param buildScriptUrl Build Script URL
211232
* @param manifestRepoUrl URL to the materialized manifest repository.
212-
* @returns Object containing the necessary run-time variables for the HLD to Manifest repository.
233+
* @returns Object containing the necessary run-time variables for the HLD to Manifest pipeline.
213234
*/
214235
export const requiredPipelineVariables = (
215236
accessToken: string,
237+
buildScriptUrl: string,
216238
manifestRepoUrl: string
217239
): { [key: string]: BuildDefinitionVariable } => {
218240
return {
241+
BUILD_SCRIPT_URL: {
242+
allowOverride: true,
243+
isSecret: false,
244+
value: buildScriptUrl
245+
},
219246
MANIFEST_REPO: {
220247
allowOverride: true,
221248
isSecret: false,

src/commands/project/pipeline.test.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import {
88
queueBuild
99
} from "../../lib/pipelines/pipelines";
1010

11-
import { installPipeline } from "./pipeline";
11+
import {
12+
installLifecyclePipeline,
13+
requiredPipelineVariables
14+
} from "./pipeline";
1215

1316
beforeAll(() => {
1417
enableVerboseLogging();
@@ -18,19 +21,44 @@ afterAll(() => {
1821
disableVerboseLogging();
1922
});
2023

24+
describe("required pipeline variables", () => {
25+
it("should use have the proper pipeline vars vars", () => {
26+
const variables = requiredPipelineVariables(
27+
"somePAT",
28+
"buildScriptUrl",
29+
"hldRepoUrl"
30+
);
31+
32+
expect(Object.keys(variables).length).toBe(3);
33+
34+
expect(variables.PAT.value).toBe("somePAT");
35+
expect(variables.PAT.isSecret).toBe(true);
36+
expect(variables.PAT.allowOverride).toBe(true);
37+
38+
expect(variables.BUILD_SCRIPT_URL.value).toBe("buildScriptUrl");
39+
expect(variables.BUILD_SCRIPT_URL.isSecret).toBe(false);
40+
expect(variables.BUILD_SCRIPT_URL.allowOverride).toBe(true);
41+
42+
expect(variables.HLD_REPO.value).toBe("hldRepoUrl");
43+
expect(variables.HLD_REPO.isSecret).toBe(false);
44+
expect(variables.HLD_REPO.allowOverride).toBe(true);
45+
});
46+
});
47+
2148
describe("create hld to manifest pipeline test", () => {
2249
it("should create a pipeline", async () => {
2350
(createPipelineForDefinition as jest.Mock).mockReturnValue({ id: 10 });
2451

2552
const exitFn = jest.fn();
26-
await installPipeline(
53+
await installLifecyclePipeline(
2754
"orgName",
2855
"PAT",
2956
"pipelineName",
3057
"repoName",
3158
"repoUrl",
3259
"hldRepoUrl",
3360
"azDoProject",
61+
"buildScriptUrl",
3462
exitFn
3563
);
3664

@@ -41,14 +69,15 @@ describe("create hld to manifest pipeline test", () => {
4169
(getBuildApiClient as jest.Mock).mockReturnValue(Promise.reject());
4270

4371
const exitFn = jest.fn();
44-
await installPipeline(
72+
await installLifecyclePipeline(
4573
"orgName",
4674
"PAT",
4775
"pipelineName",
4876
"repoName",
4977
"repoUrl",
5078
"hldRepoUrl",
5179
"azDoProject",
80+
"buildScriptUrl",
5281
exitFn
5382
);
5483

@@ -62,14 +91,15 @@ describe("create hld to manifest pipeline test", () => {
6291
);
6392

6493
const exitFn = jest.fn();
65-
await installPipeline(
94+
await installLifecyclePipeline(
6695
"orgName",
6796
"PAT",
6897
"pipelineName",
6998
"repoName",
7099
"repoUrl",
71100
"hldRepoUrl",
72101
"azDoProject",
102+
"buildScriptUrl",
73103
exitFn
74104
);
75105

@@ -82,14 +112,15 @@ describe("create hld to manifest pipeline test", () => {
82112
(queueBuild as jest.Mock).mockReturnValue(Promise.reject());
83113

84114
const exitFn = jest.fn();
85-
await installPipeline(
115+
await installLifecyclePipeline(
86116
"orgName",
87117
"PAT",
88118
"pipelineName",
89119
"repoName",
90120
"repoUrl",
91121
"hldRepoUrl",
92122
"azDoProject",
123+
"buildScriptUrl",
93124
exitFn
94125
);
95126

0 commit comments

Comments
 (0)