MCPcopy
hub / github.com/firecow/gitlab-ci-local / _predefinedVariables

Method _predefinedVariables

src/job.ts:315–358  ·  view source on GitHub ↗

* Get the predefinedVariables that's enriched with the additional info that's only available when constructing

(opt: JobOptions)

Source from the content-addressed store, hash-verified

313 * Get the predefinedVariables that's enriched with the additional info that's only available when constructing
314 */
315 private _predefinedVariables (opt: JobOptions) {
316 const argv = this.argv;
317 const cwd = argv.cwd;
318 const stateDir = this.argv.stateDir;
319 const gitData = this.gitData;
320
321 let ciBuildsDir: string;
322 if (this.jobData["image"]) {
323 ciBuildsDir = "/builds";
324 this.ciProjectDir = `${ciBuildsDir}/${gitData.remote.group}/${gitData.remote.project}`;
325 } else if (argv.shellIsolation) {
326 ciBuildsDir = `${cwd}/${stateDir}/builds/${this.safeJobName}`;
327 this.ciProjectDir = ciBuildsDir;
328 } else {
329 ciBuildsDir = cwd;
330 this.ciProjectDir = ciBuildsDir;
331 }
332
333 const predefinedVariables = opt.predefinedVariables;
334
335 predefinedVariables["CI_JOB_ID"] = `${this.jobId}`;
336 predefinedVariables["CI_PIPELINE_ID"] = `${this.pipelineIid + 1000}`;
337 predefinedVariables["CI_PIPELINE_IID"] = `${this.pipelineIid}`;
338 predefinedVariables["CI_JOB_NAME"] = `${this.name}`;
339 predefinedVariables["CI_JOB_NAME_SLUG"] = `${this.name.replaceAll(/[^a-z\d]+/ig, "-").replace(/^-/, "").slice(0, 63).replace(/-$/, "").toLowerCase()}`;
340 predefinedVariables["CI_JOB_STAGE"] = `${this.stage}`;
341 predefinedVariables["CI_BUILDS_DIR"] = ciBuildsDir;
342 predefinedVariables["CI_PROJECT_DIR"] = this.ciProjectDir;
343 predefinedVariables["CI_JOB_URL"] = `${predefinedVariables["CI_SERVER_URL"]}/${gitData.remote.group}/${gitData.remote.project}/-/jobs/${this.jobId}`; // Changes on rerun.
344 predefinedVariables["CI_PIPELINE_URL"] = `${predefinedVariables["CI_SERVER_URL"]}/${gitData.remote.group}/${gitData.remote.project}/pipelines/${this.pipelineIid}`;
345 predefinedVariables["CI_ENVIRONMENT_NAME"] = this.environment?.name ?? "";
346 predefinedVariables["CI_ENVIRONMENT_SLUG"] = this.environment?.name ? this._generateEnvironmentSlug(this.environment.name) : "";
347 predefinedVariables["CI_ENVIRONMENT_URL"] = this.environment?.url ?? "";
348 predefinedVariables["CI_ENVIRONMENT_TIER"] = this.environment?.deployment_tier ?? "";
349 predefinedVariables["CI_ENVIRONMENT_ACTION"] = this.environment?.action ?? "";
350
351 if (opt.nodeIndex !== null) {
352 predefinedVariables["CI_NODE_INDEX"] = `${opt.nodeIndex}`;
353 }
354 predefinedVariables["CI_NODE_TOTAL"] = `${opt.nodesTotal}`;
355 predefinedVariables["CI_REGISTRY"] = predefinedVariables["CI_REGISTRY"] = this.argv.registry ? Utils.gclRegistryPrefix : `local-registry.${this.gitData.remote.host}`;
356 predefinedVariables["CI_REGISTRY_IMAGE"] = `$CI_REGISTRY/${predefinedVariables["CI_PROJECT_PATH"].toLowerCase()}`;
357 return predefinedVariables;
358 }
359
360 /**
361 * Generates a compliant slug for an environment name.

Callers 1

constructorMethod · 0.95

Calls 1

Tested by

no test coverage detected