diff --git a/vars/dataset.groovy b/vars/dataset.groovy index 965d33b..8765ffb 100644 --- a/vars/dataset.groovy +++ b/vars/dataset.groovy @@ -7,7 +7,7 @@ String credentials = config['credentials'] String baseURI = config['base_uri'] - def draftset = drafter.findDraftset(PMD, credentials, env.JOB_NAME as String) // assume it already exists + def draftset = drafter.findOrCreateDraftset(PMD, credentials, env.JOB_NAME as String) // assume it already exists String datasetPath = util.slugise(datasetLabel) String datasetGraph = "${baseURI}/graph/${datasetPath}" diff --git a/vars/drafter.groovy b/vars/drafter.groovy index be0cf40..469136a 100644 --- a/vars/drafter.groovy +++ b/vars/drafter.groovy @@ -23,6 +23,18 @@ } } +def findOrCreateDraftset(String baseUrl, String credentials, String displayName) { + echo "Finding or creating draftset with display name '${displayName}'" + + def drafts = listDraftsets(baseUrl, credentials, 'owned') + def draftset = drafts.find { it['display-name'] == displayName } + if (draftset) { + draftset + } else { + createDraftset(baseUrl, credentials, displayName) + } +} + def deleteDraftset(String baseUrl, String credentials, String id) { echo "Deleting draftset ${id}" def response = httpRequest(acceptType: 'APPLICATION_JSON', diff --git a/vars/uploadTidy.groovy b/vars/uploadTidy.groovy index 6b00cf8..69ed530 100644 --- a/vars/uploadTidy.groovy +++ b/vars/uploadTidy.groovy @@ -29,7 +29,7 @@ echo 'No old job draft to delete' } - def newJobDraft = drafter.createDraftset(PMD, credentials, env.JOB_NAME) + def newJobDraft = drafter.findOrCreateDraftset(PMD, credentials, env.JOB_NAME) dataset.delete(env.JOB_NAME) if (oldLabel) {