All checks were successful
gitea.arg.rip/deployment/pipeline/head This commit looks good
190 lines
7.6 KiB
Groovy
190 lines
7.6 KiB
Groovy
pipeline {
|
|
agent any
|
|
parameters {
|
|
string(name: 'videoname', description: "video name")
|
|
string(name: 'videodesc', description: "video description")
|
|
}
|
|
environment {
|
|
JENKINSONGITEA=credentials('d0e86441-2157-405f-8539-a9a9010c6ecf')
|
|
JENKINSONMATRIXTOKEN=credentials('17d18fd7-29eb-4957-9532-ce42aaa9b4ec')
|
|
GITEAONMATRIXTOKEN=credentials('10bc888a-cb19-456e-b793-f85ee465d58e')
|
|
}
|
|
|
|
stages {
|
|
stage("environment setup") {
|
|
steps{
|
|
script{
|
|
if (videoname.isEmpty()) {
|
|
error("videoname mandatory")
|
|
}
|
|
if (videoname.contains(' ')) {
|
|
error("videoname cannot have spaces. try dashes.")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage("create gitea project"){
|
|
steps{
|
|
script{
|
|
env.giteaCreateEvent=sh(returnStdout: true, script: """
|
|
curl -X 'POST' \
|
|
'https://gitea.arg.rip/api/v1/repos/beefhavers/_videotemplate/generate' \
|
|
-H 'accept: application/json' \
|
|
-H 'Authorization: token ${env.JENKINSONGITEA}' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"description": "${videodesc}",
|
|
"git_content": true,
|
|
"git_hooks": true,
|
|
"labels": true,
|
|
"name": "${videoname}",
|
|
"owner": "beefhavers",
|
|
"private": false,
|
|
"protected_branch": true,
|
|
"topics": true,
|
|
"webhooks": true
|
|
}'
|
|
""").trim()
|
|
if (!env.giteaCreateEvent?.trim()) {
|
|
error "couldn't make gitea repo, apparently"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage("create matrix room"){
|
|
steps{
|
|
script{
|
|
env.roomcreationevent=sh(returnStdout: true, script: """
|
|
curl -X 'POST' \
|
|
'https://greyn.club:8448/_matrix/client/v3/createRoom' \
|
|
-H 'accept: application/json' \
|
|
-H 'Authorization: Bearer ${JENKINSONMATRIXTOKEN}' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"creation_content": {
|
|
"m.federate": false
|
|
},
|
|
"name": "${videoname}",
|
|
"preset": "public_chat",
|
|
"invite": ["@adam:greyn.club", "@gitea:greyn.club"],
|
|
"topic": "https://gitea.arg.rip/beefhavers/${videoname}"
|
|
}'
|
|
"""
|
|
).trim()
|
|
if (!env.roomcreationevent?.trim()) {
|
|
error "couldn't make matrix room, apparently"
|
|
}
|
|
echo "roomcreationevent:"
|
|
echo env.roomcreationevent
|
|
def jsonObj = readJSON text: env.roomcreationevent
|
|
env.room_id =jsonObj.room_id
|
|
if(!env.room_id?.trim()){
|
|
error "couldn't make matrix room, apparently"
|
|
}
|
|
|
|
env.spaceaddevent=sh(returnStdout: true, script: """
|
|
curl -X 'PUT' 'https://greyn.club:8448/_matrix/client/r0/rooms/!xLgVvcqtVzquTkCQGx:greyn.club/state/m.space.child/${env.room_id}' \
|
|
-H 'accept: application/json' \
|
|
-H 'Authorization: Bearer ${JENKINSONMATRIXTOKEN}' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"via": ["greyn.club"]
|
|
}'
|
|
""").trim()
|
|
echo "spaceaddevent:"
|
|
echo env.spaceaddevent
|
|
|
|
env.elevatePrivsEvent=sh(returnStdout: true, script: """
|
|
curl -X 'PUT' 'https://greyn.club:8448/_matrix/client/v3/rooms/${env.room_id}/state/m.room.power_levels' \
|
|
-H 'accept: application/json' \
|
|
-H 'Authorization: Bearer ${JENKINSONMATRIXTOKEN}' \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{
|
|
"users": {
|
|
"@adam:greyn.club": 100,
|
|
"@jenkins:greyn.club": 50
|
|
}
|
|
}'
|
|
""").trim()
|
|
echo "elevatePrivsEvent:"
|
|
echo env.elevatePrivsEvent
|
|
}
|
|
}
|
|
}
|
|
stage("tweak Jenkinsfile"){
|
|
steps{
|
|
withCredentials([sshUserPrivateKey(credentialsId: 'f42347e9-e3b5-44af-a1af-c5e7b9775fee', keyFileVariable: 'PK')]) {
|
|
sh """#!/bin/bash
|
|
#mkdir -p ~/.ssh
|
|
ssh-keyscan -t ed25519 gitea.arg.rip >> ~/.ssh/known_hosts
|
|
#cat ~/.ssh/known_hosts
|
|
#shit doesn't work. ssh in, git clone, get your shit set up for keys.
|
|
git -c core.sshCommand="ssh -i '$PK'\" clone ssh://git@gitea.arg.rip:8022/beefhavers/${videoname}.git
|
|
"""
|
|
script {
|
|
sh """#!/bin/bash
|
|
pushd ${videoname}
|
|
|
|
sed -i 's/MATRIX_ROOMID="todo"/MATRIX_ROOMID="${env.room_id}"/' Jenkinsfile
|
|
|
|
git add .
|
|
git commit -m "matrix room configured in jenkinsfile"
|
|
git -c core.sshCommand="ssh -i '${PK}'\" push
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
stage("link gitea webhook"){
|
|
steps{
|
|
sh """
|
|
curl -X 'GET' 'https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks' \
|
|
-H 'accept: application/json' \
|
|
-H 'authorization: token ${env.JENKINSONGITEA}' \
|
|
>reporesponse.json
|
|
|
|
cat reporesponse.json
|
|
cat reporesponse.json | jq '.[] | select(.type=="matrix")' >matrixhook.json
|
|
cat matrixhook.json
|
|
|
|
"""
|
|
|
|
sh """
|
|
echo '{
|
|
"active": true,
|
|
"authorization_header": "Bearer ${env.GITEAONMATRIXTOKEN}",
|
|
"branch_filter": "*",
|
|
"config": {
|
|
"content_type": "json",' >request.json
|
|
echo "\\"url\\": \\"https://greyn.club:8448/_matrix/client/r0/rooms/\$(echo ${env.room_id} | sed 's/!/%21/')/send/m.room.message\\"" >>request.json
|
|
echo "}," >>request.json
|
|
echo "\\"events\\": \$(cat matrixhook.json | jq .[0].events)" >>request.json
|
|
echo '}' >>request.json
|
|
|
|
cat request.json
|
|
"""
|
|
|
|
//delete old
|
|
sh """
|
|
curl -X 'DELETE' "https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks/\$(cat matrixhook.json | jq .[0].id)" \
|
|
-H 'accept: application/json' \
|
|
-H 'authorization: token ${env.JENKINSONGITEA}' \
|
|
"""
|
|
|
|
//make a new one
|
|
sh """
|
|
curl -X 'POST' "https://gitea.arg.rip/api/v1/repos/beefhavers/${videoname}/hooks" \
|
|
-H 'accept: application/json' \
|
|
-H 'authorization: token ${env.JENKINSONGITEA}' \
|
|
-H 'Content-Type: application/json' \
|
|
-d @request.json
|
|
|
|
rm request.json
|
|
rm reporesponse.json
|
|
rm matrixhook.json
|
|
"""
|
|
}
|
|
}
|
|
}
|
|
}
|