Util.getPipelineExecutionId = function()

in pipeline/local_modules/pipeline_utils/pipeline_utils.js [275:303]


Util.getPipelineExecutionId = function (pipelineName, stageName, actionName, lambdaFunctionName, actionMustBeRunningNow = false) {
  var params = {
    name: pipelineName
  };
  return codePipeline.getPipelineState(params).promise()
    .then(function (response) {
      var stageState = response.stageStates.filter(stage => stage.stageName === stageName);
      if (stageState.length === 0) {
        throw "Could not find pipeline stage: '" + pipelineStage + "' while finding out the pipeline executionId";
      }
      if (actionName !== undefined) {
        var actionState = stageState[0].actionStates.filter(actionState => actionState.actionName === actionName);
        if (actionState.length === 0) {
          throw "Could not find pipeline action: '" + actionName + "' while finding out the pipeline executionId";
        }
        if (lambdaFunctionName !== undefined) {
          if (!actionState[0].entityUrl.endsWith(lambdaFunctionName)) {
            console.log("ActionState: " + JSON.stringify(actionState[0]));
            throw "Found a different entityURL: ('" + actionState[0].entityUrl + "' not ending with the expected function name '" + lambdaFunctionName + "') being called by pipeline action: " + actionName + " while finding out the pipeline executionId";
          }
        }
        if (actionMustBeRunningNow && actionState[0].latestExecution.status !== 'InProgress') {
          throw "Action: '" + actionName + "' is not currently 'InProgress' in the pipeline while finding out the pipeline executionId (latest action state is '" + actionState[0].latestExecution.status + "')";
        }
      }
      return stageState[0].latestExecution.pipelineExecutionId;
      //  return Promise.resolve(stageState[0].latestExecution.pipelineExecutionId);
    });
}