79308924

Date: 2024-12-26 07:34:05
Score: 0.5
Natty:
Report link

Use a Root Privileged Script Run the deletion process as part of a script executed by a privileged user.

Steps:

  1. Create a script, e.g., /usr/local/bin/delete_dir.sh:

    #!/bin/bash rm -rf /path/to/directory

  2. Grant execution permission:

    sudo chmod +x /usr/local/bin/delete_dir.sh

  3. Allow Jenkins to execute it via sudo:

    sudo visudo

  4. Add the line:

    jenkins ALL=(ALL) NOPASSWD: /usr/local/bin/delete_dir.sh

  5. Update the Jenkins pipeline stage:

    stage('Delete Directory') { steps { script { sh 'sudo /usr/local/bin/delete_dir.sh' } } }

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Saurabh Gupta