🚢 Deployments are not associating with the Merge Request

I’m attempting to create a Deployment badge on a Merge Request, similar to the Github feature.

:fox_face: To reproduce

  • I’m listening for a Merge Request webhook
  • I use gitbeaker to create an environment
    • projectId - the project used
    • environmentName - {internalSlug}-{branch}
    • externalUrl - URL of the MR preview
    • tier - I’ve attempted to set this to nothing, production, staging and development.
  • I use gitbeaker to create the deployment
    • projectId - same as before
    • environmentName - same as before
    • branchSha - from MR webhook
    • branchName - from. MR webhook
    • tag - false (there’s an active issue with gitbeaker)
    • status - success

:test_tube: Debugging

:balloon: Additional Information

I think this is related to this line of code.

:robot: Code

Here’s an example I was able to extract that shows how I attempted to create this. I can remove gitbeaker and use fetch if that’s useful, but I think this communicates the issue well.

Here is the local-baylee-test-4 environment this created.

import { Gitlab } from '@gitbeaker/rest';
import Cryptr from 'cryptr';

const environmentName = 'local-baylee-test-4';
const projectId = 60797798;
const branchSha = 'bab448c854d04a1ce13d5b302ef548c025986dbd';
const branchName = 'lab-1';
const externalUrl = 'https://mintlify.com/?princess=wiggles';
const encryptedToken = '';

export const cryptr = new Cryptr(process.env.ENCRYPTION_PASSWORD);
const beaker = new Gitlab({
  host: 'https://gitlab.com',
  token: cryptr.decrypt(encryptedToken),
});

async function findMRs(deploymentId) {
  const mrs = await beaker.Deployments.allMergeRequests(projectId, deploymentId);
  console.log(mrs);
  return mrs;
}

async function createGitlabEnvironment() {
  const environment = await beaker.Environments.create(projectId, environmentName, {
    externalUrl,
  });
  console.log({environment});
  return environment;
}

async function createGitlabDeployment(environment) {
  const deployment = await beaker.Deployments.create(
    projectId,
    environment.name,
    branchSha,
    branchName,
    false,
    {
      status: 'success',
    }
  );
  console.log({deployment});
  return deployment;
}

const newEnvironment = await createGitlabEnvironment();
const deployment = await createGitlabDeployment(newEnvironment);

await findMRs(deployment.id);
1 Like