From ac0675df94fcb89cede7e5c03831d575ae1c586b Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 3 Dec 2024 00:21:42 -0500 Subject: [PATCH] CREDS GO IN --- scripts/1clickservice.groovy | 53 +++++++++++++++++------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/scripts/1clickservice.groovy b/scripts/1clickservice.groovy index a535dfb..7e3e511 100644 --- a/scripts/1clickservice.groovy +++ b/scripts/1clickservice.groovy @@ -12,7 +12,7 @@ pipeline { //pw_developmentdatabase="" //SUDOER=credentials('') //going to be set based on target host SUDOERSSH=credentials('2c48e1a9-22b2-455c-9959-6b29e86d3fb5') - JENKINS=credentials('f1192e74-dfe0-402f-a189-703482d914fe') + JENKINS=credentials('68391381-e095-4b47-b956-d23055b0808e') GITEATOKEN = credentials('d0e86441-2157-405f-8539-a9a9010c6ecf') } stages { @@ -36,11 +36,11 @@ pipeline { error("target host not recognized. btw: yes .lan, all lowercase.") } - env.pw_linuxserviceaccount=sh(returnStdout: true, script: "mktemp -u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + env.pw_linuxserviceaccount=sh(returnStdout: true, script: "mktemp -u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").trim() echo env.pw_linuxserviceaccount - env.pw_productiondatabase=sh(returnStdout: true, script: "mktemp -u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + env.pw_productiondatabase=sh(returnStdout: true, script: "mktemp -u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").trim() echo env.pw_productiondatabase - env.pw_developmentdatabase=sh(returnStdout: true, script: "mktemp -u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") + env.pw_developmentdatabase=sh(returnStdout: true, script: "mktemp -u XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX").trim() echo env.pw_developmentdatabase } } @@ -83,8 +83,9 @@ pipeline { while [ -z "\$strRes" ]; do sleep 5; - curl -X GET -s -u ${env.JENKINS_USR}:'${env.JENKINS_PSW}' \ - alloces.lan:8080/job/gitea.arg.rip/api/json > f.json + #curl -X GET ${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/api/json + curl -X GET -s ${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/api/json > f.json + strRes=\$(jq '.jobs' f.json | jq '.[] | select(.name==\"${env.servicename}\")') rm f.json done @@ -107,33 +108,29 @@ pipeline { pushd ${servicename} dbstartline=\$(sed -n '/---dbstart---/=' Jenkinsfile) dbendline=\$(sed -n '/---dbend---/=' Jenkinsfile) - echo \"yes db. \${dbstartline} and \${dbendline}\" + echo \"yes db.\" - sed -ie \"\${dbstartline}d;\${dbendline}d\" Jenkinsfile + sed -i \"\${dbstartline}d;\${dbendline}d\" Jenkinsfile databasecredsid=\$(uuidgen) - urlGetData=\"crumbIssuer/api/xml?xpath=concat\\(//crumbRequestField,\\":\\",//crumb\\)\" - echo "116" - echo \"\${urlGetData}\" - echo "118" - echo \'curl -s \"http://${env.JENKINS_USR}:\\\'${env.JENKINS_PSW}\\\'@alloces.lan:8080/\${urlGetData}\"\' - echo "122" - curl -s \"http://${env.JENKINS_USR}:\\\'${env.JENKINS_PSW}\\\'@alloces.lan:8080/\${urlGetData}\" - - CRUMB=\$(curl -s \"http://${env.JENKINS_USR}:\\\'${env.JENKINS_PSW}\\\'@alloces.lan:8080/\${urlGetData}\") - echo \$CRUMB - curl -H \$CRUMB -X POST \"http://${env.JENKINS_USR}:'${env.JENKINS_PSW}'@alloces.lan:8080/job/gitea.arg.rip/job/${servicename}/credentials/store/folder/domain/greyn%20services/createCredentials\" \ + httpBasicAuth=\"http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/\" + echo \"\${httpBasicAuth}\" + urlGetData=\"crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\\":\\",//crumb)\" + + CRUMB=\$(curl -s -c cookies.txt \"\${httpBasicAuth}\${urlGetData}\") + echo "crumb anyway. \$CRUMB" + curl -H \$CRUMB -X POST \"http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/job/${servicename}/credentials/store/folder/domain/_/createCredentials\" \ --data-urlencode 'json={ "": "0", "credentials": { "scope": "GLOBAL", - "id": "\$databasecredsid", - "secret": "\"Host=${targetHost};Database=${servicename};Username=${servicename};Password=${env.pw_productiondatabase};IncludeErrorDetail=true;\"", + "id": "'"\$databasecredsid"'", + "secret": "Host=${targetHost};Database=${servicename};Username=${servicename};Password=${env.pw_productiondatabase};IncludeErrorDetail=true;", "description": "database connection string", "\$class": "com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl" } }' - sed -ie 's/productiondatabase_connectionString=creds/productiondatabase_connectionString=credentials('\$databasecredsid')/\' Jenkinsfile + sed -i 's/productiondatabase_connectionString=creds/productiondatabase_connectionString=credentials('\$databasecredsid')/\' Jenkinsfile git add . git commit -m \"set up for database\" @@ -153,9 +150,9 @@ pipeline { usernameCredsId=\$(uuidgen) - CRUMB=\$(curl 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') - echo \$CRUMB - curl -H \$CRUMB -X POST 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/job/${servicename}/credentials/store/folder/domain/greyn%20services/createCredentials' \ + #CRUMB=\$(curl -c cookies.txt 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') + #echo \$CRUMB + curl -X POST 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/job/${servicename}/credentials/store/folder/domain/_/createCredentials' \ --data-urlencode 'json={ "": "0", "credentials": { @@ -174,9 +171,9 @@ pipeline { ssh-keygen -t ed25519 -f "${servicename}" -N "" privatekeycontent=\$(cat ${servicename})) pubkeycontent=\$(cat ${servicename}.pub)) - CRUMB=\$(url -s 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') - echo \$CRUMB - curl -H \$CRUMB -X POST 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/job/${servicename}/credentials/store/folder/domain/greyn%20services/createCredentials' \ + #CRUMB=\$(curl -s -c cookies.txt 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') + #echo \$CRUMB + curl -X POST 'http://${env.JENKINS_USR}:${env.JENKINS_PSW}@alloces.lan:8080/job/gitea.arg.rip/job/${servicename}/credentials/store/folder/domain/_/createCredentials' \ --data-urlencode 'json={ "": "0", "credentials": {