I have a code which is supposed to check if some repository exists on the remote repository manager and if the result is correct then the execution of the following .then() statements should be stopped.
My main function:
execGitCommand(projectDir, `clone -b ${sourceBranch} ${projectDescription.url} ${projectDir}`, false)
.then(() => loadProjectPoms(projectDir, projectPoms))
.then((value) => {
projectPomDescription = value;
return checkIfProjectExistsOnNexus(projectPomDescription, projectDescription)
})
.then(() => execGitCommand(projectDir, `rebase origin/${destinationBranch}`))
.then(() => updateProjectVersion(projectDescription, projectDir))
.then(() => updateProjectPoms(projectDescription, projectDir))
.then(() => execGitCommand(projectDir,"add -u"))
.then(() => execGitCommand(projectDir,`commit -m "Set version ${projectDescription.version}"`))
.then(() => execGitCommand(projectDir,`push origin ${sourceBranch}`)
.then(waitingCallback)
.then(() => waitNexusRelease(projectDescription, projectPoms, projectPomDescription, project))
.then(completeCallback)
.catch(errorCallback))
So, when the function checkIfProjectExistsOnNexus
is rejected i would like to stop executing the next .then commands (.then(() => execGitCommand(projectDir,rebase origin/${destinationBranch}
)) and so on)
The function checkIfProjectExistsOnNexus
:
function checkIfProjectExistsOnNexus(projectPomDescription, projectDescription) {
return new Promise((resolve, reject) => {
const version = ((argv.type === 'snapshot') ? projectDescription.version.replace('SNAPSHOT','*') : projectDescription.version);
nexus.exists(getProjectGroupId(projectPomDescription), projectPomDescription.project.artifactId, version)
.then((value) => {
console.log("value "+ value)
if (value) {
console.log(`Project: ${projectDescription.name} has already been released in version ${projectDescription.version}, project skipped.`);
reject();
return;
}
resolve();
}).catch(reject);
}).catch(() => console.log(`Error occurred while checking if project exists on Nexus.`));
}
After calling return
after reject()
statement the following commands are still being further executed. They should be only executed when function does not go into if statement in checkIfProjectExistsOnNexus
function.
Thanks in advance.