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

Commit dc19cbf

Browse files
committed
Pass pipelines yaml file path to repository file check
1 parent a623bd8 commit dc19cbf

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/commands/service/pipeline.test.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,57 @@ describe("required pipeline variables", () => {
118118
describe("create pipeline tests", () => {
119119
it("should create a pipeline", async () => {
120120
(createPipelineForDefinition as jest.Mock).mockReturnValueOnce({ id: 10 });
121-
await installBuildUpdatePipeline("serviceName", MOCKED_VALUES);
121+
await installBuildUpdatePipeline(
122+
"serviceName",
123+
"/path/to/yaml",
124+
MOCKED_VALUES
125+
);
122126
});
127+
123128
it("should fail if the build client cant be instantiated", async () => {
124129
(getBuildApiClient as jest.Mock).mockReturnValueOnce(Promise.reject());
125130

126131
try {
127-
await installBuildUpdatePipeline("serviceName", MOCKED_VALUES);
132+
await installBuildUpdatePipeline(
133+
"serviceName",
134+
"/path/to/yaml",
135+
MOCKED_VALUES
136+
);
128137
expect(true).toBe(false);
129138
} catch (_) {
130139
// expecting exception to be thrown
131140
}
132141
});
142+
133143
it("should fail if the pipeline definition cannot be created", async () => {
134144
(getBuildApiClient as jest.Mock).mockReturnValueOnce({});
135145
(createPipelineForDefinition as jest.Mock).mockReturnValueOnce(
136146
Promise.reject()
137147
);
138148

139149
try {
140-
await installBuildUpdatePipeline("serviceName", MOCKED_VALUES);
150+
await installBuildUpdatePipeline(
151+
"serviceName",
152+
"/path/to/yaml",
153+
MOCKED_VALUES
154+
);
141155
expect(true).toBe(false);
142156
} catch (_) {
143157
// expecting exception to be thrown
144158
}
145159
});
160+
146161
it("should fail if a build cannot be queued on the pipeline", async () => {
147162
(getBuildApiClient as jest.Mock).mockReturnValueOnce({});
148163
(createPipelineForDefinition as jest.Mock).mockReturnValueOnce({ id: 10 });
149164
(queueBuild as jest.Mock).mockReturnValueOnce(Promise.reject());
150165

151166
try {
152-
await installBuildUpdatePipeline("serviceName", MOCKED_VALUES);
167+
await installBuildUpdatePipeline(
168+
"serviceName",
169+
"/path/to/yaml",
170+
MOCKED_VALUES
171+
);
153172
expect(true).toBe(false);
154173
} catch (_) {
155174
// expecting exception to be thrown

src/commands/service/pipeline.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
SERVICE_PIPELINE_FILENAME
1414
} from "../../lib/constants";
1515
import { IAzureDevOpsOpts } from "../../lib/git";
16-
import { GitAPI } from "../../lib/git/azure";
1716
import {
1817
getOriginUrl,
1918
getRepositoryName,
@@ -81,14 +80,21 @@ export const execute = async (
8180
project: opts.devopsProject
8281
};
8382

83+
// if a packages dir is supplied, its a mono-repo
84+
const pipelinesYamlPath = opts.packagesDir
85+
? // if a packages dir is supplied, concat <packages-dir>/<service-name>
86+
path.join(opts.packagesDir, serviceName, SERVICE_PIPELINE_FILENAME)
87+
: // if no packages dir, then just concat with the service directory.
88+
path.join(serviceName, SERVICE_PIPELINE_FILENAME);
89+
8490
// By default the version descriptor is for the master branch
8591
await repositoryHasFile(
86-
SERVICE_PIPELINE_FILENAME,
92+
pipelinesYamlPath,
8793
opts.yamlFileBranch ? opts.yamlFileBranch : "master",
8894
opts.repoName,
8995
accessOpts
9096
);
91-
await installBuildUpdatePipeline(serviceName, opts);
97+
await installBuildUpdatePipeline(serviceName, pipelinesYamlPath, opts);
9298
await exitFn(0);
9399
} catch (err) {
94100
logger.error(err);
@@ -112,10 +118,12 @@ export const commandDecorator = (command: commander.Command) => {
112118
* @param serviceName Name of the service this pipeline belongs to;
113119
* this is only used when `packagesDir` is defined as a means
114120
* to locate the azure-pipelines.yaml file
121+
* @param pipelinesYamlPath Relative path to the build update hld pipelines yaml file in the repository
115122
* @param values Values from commander
116123
*/
117124
export const installBuildUpdatePipeline = async (
118125
serviceName: string,
126+
pipelinesYamlPath: string,
119127
values: ICommandOptions
120128
) => {
121129
let devopsClient: IBuildApi | undefined;
@@ -128,13 +136,6 @@ export const installBuildUpdatePipeline = async (
128136
);
129137
logger.info("Fetched DevOps Client");
130138

131-
// if a packages dir is supplied, its a mono-repo
132-
const yamlFilePath = values.packagesDir
133-
? // if a packages dir is supplied, concat <packages-dir>/<service-name>
134-
path.join(values.packagesDir, serviceName, SERVICE_PIPELINE_FILENAME)
135-
: // if no packages dir, then just concat with the service directory.
136-
path.join(serviceName, SERVICE_PIPELINE_FILENAME);
137-
138139
const definition = definitionForAzureRepoPipeline({
139140
branchFilters: ["master"],
140141
maximumConcurrentBuilds: 1,
@@ -143,7 +144,7 @@ export const installBuildUpdatePipeline = async (
143144
repositoryUrl: values.repoUrl,
144145
variables: requiredPipelineVariables(values.buildScriptUrl),
145146
yamlFileBranch: values.yamlFileBranch,
146-
yamlFilePath
147+
yamlFilePath: pipelinesYamlPath
147148
});
148149

149150
logger.debug(
@@ -153,7 +154,7 @@ export const installBuildUpdatePipeline = async (
153154
);
154155

155156
logger.info(
156-
`Attempting to create new pipeline: ${values.pipelineName} defined in repository:${values.repoUrl}, branch: ${values.yamlFileBranch}, filePath: ${yamlFilePath}`
157+
`Attempting to create new pipeline: ${values.pipelineName} defined in repository:${values.repoUrl}, branch: ${values.yamlFileBranch}, filePath: ${pipelinesYamlPath}`
157158
);
158159

159160
builtDefinition = await createPipelineForDefinition(

0 commit comments

Comments
 (0)