feat(gitea): add download() method
This commit is contained in:
@ -44,15 +44,15 @@ def commentPullRequest(String repo, String issueId, String comment, Integer comm
|
||||
}
|
||||
|
||||
// Effectue une "release" sur Gitea pour le <ORG>/<PROJET> donné.
|
||||
def release(String credentialsId, String org, String project, Map options = [:]) {
|
||||
def isDraft = options.get('isDraft', false)
|
||||
def baseUrl = options.get('baseUrl', 'https://forge.cadoles.com')
|
||||
def defaultVersion = sh(returnStdout: true, script: 'git describe --always').trim()
|
||||
def releaseVersion = options.get('releaseVersion', defaultVersion)
|
||||
def releaseName = options.get('releaseName', releaseVersion)
|
||||
def commitishTarget = options.get('commitishTarget', env.GIT_COMMIT)
|
||||
void release(String credentialsId, String org, String project, Map options = [:]) {
|
||||
Boolean isDraft = options.get('isDraft', false)
|
||||
String baseUrl = options.get('baseUrl', 'https://forge.cadoles.com')
|
||||
String defaultVersion = sh(returnStdout: true, script: 'git describe --always').trim()
|
||||
String releaseVersion = options.get('releaseVersion', defaultVersion)
|
||||
String releaseName = options.get('releaseName', releaseVersion)
|
||||
String commitishTarget = options.get('commitishTarget', env.GIT_COMMIT)
|
||||
|
||||
def defaultIsPrerelease = true
|
||||
Boolean defaultIsPrerelease = true
|
||||
try {
|
||||
sh(script: "git describe --exact-match ${GIT_COMMIT}")
|
||||
defaultIsPrerelease = false
|
||||
@ -60,16 +60,16 @@ def release(String credentialsId, String org, String project, Map options = [:])
|
||||
println "Could not find tag associated with commit '${GIT_COMMIT}' ! Using 'prerelease' as default."
|
||||
}
|
||||
|
||||
def isPrerelease = options.get('isPrerelease', defaultIsPrerelease)
|
||||
def body = options.get('body', '')
|
||||
def attachments = options.get('attachments', [])
|
||||
Boolean isPrerelease = options.get('isPrerelease', defaultIsPrerelease)
|
||||
String body = options.get('body', '')
|
||||
List<String> attachments = options.get('attachments', [])
|
||||
|
||||
def scriptTempDir = ".gitea-release-script-${System.currentTimeMillis()}"
|
||||
String scriptTempDir = ".gitea-release-script-${System.currentTimeMillis()}"
|
||||
sh("mkdir -p '${scriptTempDir}'")
|
||||
|
||||
def giteaReleaseScript = "${scriptTempDir}/gitea-release.sh"
|
||||
String giteaReleaseScript = "${scriptTempDir}/gitea-release.sh"
|
||||
|
||||
def giteaReleaseScriptContent = libraryResource 'com/cadoles/gitea/gitea-release.sh'
|
||||
String giteaReleaseScriptContent = libraryResource 'com/cadoles/gitea/gitea-release.sh'
|
||||
writeFile file: giteaReleaseScript, text:giteaReleaseScriptContent
|
||||
sh("chmod +x '${giteaReleaseScript}'")
|
||||
|
||||
@ -102,3 +102,43 @@ def release(String credentialsId, String org, String project, Map options = [:])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Télécharge les fichiers associés à une "version" publiée sur un projet Gitea
|
||||
void download(String credentialsId, String org, String project, Map options = [:]) {
|
||||
String baseUrl = options.get('baseUrl', 'https://forge.cadoles.com')
|
||||
String releaseName = options.get('releaseName', 'latest')
|
||||
String outputDir = options.get('outputDir', 'gitea-dl')
|
||||
|
||||
String scriptTempDir = ".gitea-download-script-${System.currentTimeMillis()}"
|
||||
sh("mkdir -p '${scriptTempDir}'")
|
||||
|
||||
String giteaDownloadScript = "${scriptTempDir}/gitea-download.sh"
|
||||
|
||||
String giteaDownloadScriptContent = libraryResource 'com/cadoles/gitea/gitea-download.sh'
|
||||
writeFile file: giteaDownloadScript, text:giteaDownloadScriptContent
|
||||
sh("chmod +x '${giteaDownloadScript}'")
|
||||
|
||||
try {
|
||||
withCredentials([
|
||||
usernamePassword(
|
||||
credentialsId: credentialsId,
|
||||
usernameVariable: 'GITEA_DOWNLOAD_USERNAME',
|
||||
passwordVariable: 'GITEA_DOWNLOAD_PASSWORD'
|
||||
)
|
||||
]) {
|
||||
sh """
|
||||
export GITEA_DOWNLOAD_PROJECT="${project}"
|
||||
export GITEA_DOWNLOAD_ORG="${org}"
|
||||
export GITEA_DOWNLOAD_BASE_URL="${baseUrl}"
|
||||
export GITEA_DOWNLOAD_RELEASE_NAME="${releaseName}"
|
||||
export GITEA_DOWNLOAD_TARGET_DIRECTORY="${outputDir}"
|
||||
|
||||
${giteaDownloadScript}
|
||||
"""
|
||||
}
|
||||
} finally {
|
||||
dir(scriptTempDir) {
|
||||
deleteDir()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user