Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: screwdriver-cd/screwdriver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: screwdriver-cd/screwdriver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: pipeline-annotation-update
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 1 file changed
  • 1 contributor

Commits on Feb 14, 2025

  1. Copy the full SHA
    3a7cd8a View commit details
Showing with 27 additions and 3 deletions.
  1. +27 −3 plugins/pipelines/update.js
30 changes: 27 additions & 3 deletions plugins/pipelines/update.js
Original file line number Diff line number Diff line change
@@ -45,10 +45,10 @@ module.exports = () => ({
},

handler: async (request, h) => {
const { checkoutUrl, rootDir, settings, badges } = request.payload;
const { checkoutUrl, rootDir, settings, badges, annotations } = request.payload;
const { id } = request.params;
const { pipelineFactory, userFactory, secretFactory } = request.server.app;
const { scmContext, username } = request.auth.credentials;
const { scmContext, username, scmUserId } = request.auth.credentials;
const scmContexts = pipelineFactory.scm.getScmContexts();
const { isValidToken } = request.server.plugins.pipelines;
const deployKeySecret = 'SD_SCM_DEPLOY_KEY';
@@ -163,6 +163,30 @@ module.exports = () => ({
}
}

if (annotations) {
const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext });
// Lookup whether user is admin
const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(
username,
scmDisplayName,
scmUserId
);

// Only cluster admins to can update pipeline annotations
if (!adminDetails.isAdmin) {
throw boom.forbidden(`Only SD cluster admin can update pipeline annotations`);

}

if (!oldPipeline.annotations) {
oldPipeline.annotations = annotations;
} else {
const newAnnotations = { ...oldPipeline.annotations, ...annotations };

oldPipeline.annotations = newAnnotations;
}
}

// update pipeline
const updatedPipeline = await oldPipeline.update();

@@ -173,7 +197,7 @@ module.exports = () => ({
// check if pipeline has deploy key annotation then create secrets
// sync needs to happen before checking annotations
const deployKeyAnnotation =
updatedPipeline.annotations && updatedPipeline.annotations[ANNOTATION_USE_DEPLOY_KEY];
updatedPipeline.annotations?.[ANNOTATION_USE_DEPLOY_KEY];

if (deployKeyAnnotation) {
const deploySecret = await secretFactory.get({