Jenkins Pipeline to execute Ranger Policy for all Rest API based on pull request

86 Views Asked by At

I have created the Jenkins pipeline below to create the Ranger Policies. As of now only creating the Ranger Policies through Ranger rest API available. But need to add rest api call for update and delete for Ranger policy update and delete.

stage('Create Policy by json') {
            steps {
        script{
              withCredentials([usernamePassword(credentialsId: 'ranger', passwordVariable: 'RANGER_PASSWORD', usernameVariable: 'RANGER_USERNAME')]) {    
             cmd = """curl -ikvvv -u ${RANGER_USERNAME}:${RANGER_PASSWORD} -H "Content-type:application/json" -X POST hostname:portnumber/service/public/api/policy/ -d @policy.json"""
              REQUEST_STATUS = sh(script:cmd, returnStdout: true).trim()
            print(REQUEST_STATUS)              
          }
          } 
          }}

Any input how I can add below curl command in same pipeline so Jenkins will understand on which pattern it has perform these operations create, update and delete individually based on pull request details. Below are curl rest api for update and delete

update: cmd = """curl -ikvvv -u ${RANGER_USERNAME}:${RANGER_PASSWORD} -H "Content-type:application/json" -X PUT hostname:portnumber/service/public/api/policy/id -d @policy.json"""

delete: cmd = """curl -ikvvv -u ${RANGER_USERNAME}:${RANGER_PASSWORD} -H "Content-type:application/json" -X DELETE hostname:portnumber/service/public/api/policy/id -d @policy.json"""

0

There are 0 best solutions below