/** * Gitea commit status utilities for Spicy Automation pipelines * * Uses the same credential as the Gitea plugin (Gitea Personal Access Token type). */ def updateStatus(Map args) { try { // For Gitea, we use the HTTP API to update commit status // This requires a Gitea API token stored in Jenkins credentials def giteaUrl = args.giteaUrl ?: env.GITEA_URL ?: 'https://git.kodeniks.com' def credentialsId = args.credentialsId ?: 'kodeniks-gitea-token' // Gitea Personal Access Token credentials store token in the password field withCredentials([usernamePassword(credentialsId: credentialsId, usernameVariable: 'GITEA_USER', passwordVariable: 'GITEA_TOKEN')]) { def repoPath = gitUtils.getRemoteURL() .replaceAll('.*[:/]([^/]+/[^/]+)\\.git$', '$1') def sha = gitUtils.getSHA() def apiUrl = "${giteaUrl}/api/v1/repos/${repoPath}/statuses/${sha}" def payload = [ state: args.state, target_url: env.BUILD_URL ?: '', description: args.message ?: '', context: "ci/jenkins/${args.context}" ] def payloadJson = groovy.json.JsonOutput.toJson(payload) // Use single quotes for shell, double quotes for curl args // $GITEA_TOKEN is a shell variable set by withCredentials sh "curl -s -X POST '${apiUrl}' -H 'Authorization: token '\"\$GITEA_TOKEN\"'' -H 'Content-Type: application/json' -d '${payloadJson}'" } } catch (err) { print "Error updating commit status, proceeding without updating: ${err.getClass().getSimpleName()}" } } def setSuccess(context) { updateStatus( context: context, state: 'success', message: 'Completed' ) } def setPending(context) { updateStatus( context: context, state: 'pending', message: 'Pending' ) } def setFailed(context) { updateStatus( context: context, state: 'failure', message: 'Failed' ) } def setError(context) { updateStatus( context: context, state: 'error', message: 'Error' ) } return this