public Result deleteTemporaryBuild ( Integer buildRecordId , String authToken ) throws ValidationException { BuildRecord buildRecord = buildRecordRepository . findByIdFetchAllProperties ( buildRecordId ) ; if ( ! buildRecord . isTemporaryBuild ( ) ) { throw new ValidationException ( "Only deletion of the temporary builds is allowed" ) ; } log . info ( "Starting deletion of a temporary build " + buildRecord + "; Built artifacts: " + buildRecord . getBuiltArtifacts ( ) + "; Dependencies: " + buildRecord . getDependencies ( ) ) ; Result result = remoteBuildsCleaner . deleteRemoteBuilds ( buildRecord , authToken ) ; if ( ! result . isSuccess ( ) ) { log . error ( "Failed to delete remote temporary builds for BR.id:{}." , buildRecord . getId ( ) ) ; return new Result ( buildRecordId . toString ( ) , Result . Status . FAILED , "Failed to delete remote temporary builds." ) ; } /** Delete relation between BuildRecord and Artifact */ Set < Artifact > artifactsToBeDeleted = new HashSet <> ( ) ; removeRelationBuildRecordArtifact ( buildRecord , artifactsToBeDeleted ) ; /** * Delete artifacts, if the artifacts are not used in other builds */ deleteArtifacts ( artifactsToBeDeleted ) ; deleteDependencies ( buildRecord ) ; buildRecordRepository . delete ( buildRecord . getId ( ) ) ; log . info ( "Deletion of the temporary build {} finished successfully." , buildRecord ) ; return new Result ( buildRecordId . toString ( ) , Result . Status . SUCCESS ) ; }
Deletes a temporary build and artifacts created during the build or orphan dependencies used