instruction: How to troubleshoot common jenkins CI/CD issues
output: It is very important to understand all of the following points because it
  affects the integrity of your Jenkins installation. The Jenkins Script Console: Access is controlled by the Administer permission. Is a web-based Groovy shell into the Jenkins runtime. Groovy is a very
  powerful language which offers the ability to do practically anything Java can
  do including: Create sub-processes and execute arbitrary commands on the Jenkins
  controller and agents. It can even read files in which the Jenkins controller has access to on
  the host (like /etc/passwd ) Decrypt credentials configured within Jenkins. Offers no administrative controls to stop a User (or Admin) once they
  are able to execute the Script Console from affecting all parts of the Jenkins
  infrastructure. Granting a normal Jenkins user Script Console Access is
  essentially the same as giving them Administrator rights within Jenkins. Can configure any Jenkins setting. It can disable security,
  reconfigure security, even open a backdoor on the host operating system
  completely outside of the Jenkins process. Due to the mission critical
  importance many organizations place on Jenkins in their infrastructure this
  point is especially important because it would allow an attacker to move
  laterally within infrastructure with little effort. Is so powerful because it was originally intended as a debugging
  interface for Jenkins developers but has since grown into an interface used by
  Jenkins Admins to configure Jenkins and debug Jenkins runtime issues. Additional security considerations for administrative scripts: Scripts can bypass all security controls and access any data. Credentials accessed via scripts are decrypted. Changes made via scripts may not be audited in the normal logs. Scripts can modify Jenkins at the lowest levels, potentially making it unstable. Because of the power offered by the Jenkins Script Console, Jenkins and its
  agents should never be run as the root user (on Linux) or system
  administrator on any other flavor of OS. Videos linked in this page demonstrate
  and discuss security warnings. Be sure to secure your Jenkins controller
  import hudson.util.RemotingDiagnostics import jenkins.model.Jenkins String agentName = 'your agent name' //groovy script you want executed on an agent groovy_script = '''
  println System.getenv("PATH")
  println "uname -a".execute().text
  ''' . trim () String result Jenkins . instance . slaves . find { agent -> agent . name == agentName }. with { agent -> result = RemotingDiagnostics . executeGroovy ( groovy_script , agent . channel ) } println result
  new File ( '/tmp/file.txt' ). withWriter ( 'UTF-8' ) { writer -> try { writer << 'hello world\n' } finally { writer . close () } }
  new File ( '/tmp/file.txt' ). text
  import hudson.FilePath import hudson.remoting.Channel import jenkins.model.Jenkins String agentName = 'some-agent' String filePath = '/tmp/file.txt' Channel agentChannel = Jenkins . instance . slaves . find { agent -> agent . name == agentName }. channel new FilePath ( agentChannel , filePath ). write (). with { os -> try { os << 'hello world\n' } finally { os . close () } }
  import hudson.FilePath import hudson.remoting.Channel import jenkins.model.Jenkins import java.io.BufferedReader import java.io.InputStreamReader import java.nio.charset.StandardCharsets import java.util.stream.Collectors String agentName = 'some-agent' String filePath = '/tmp/file.txt' Channel agentChannel = Jenkins . instance . slaves . find { agent -> agent . name == agentName }. channel String fileContents = '' new FilePath ( agentChannel , filePath ). read (). with { is -> try { fileContents = new BufferedReader ( new InputStreamReader ( is , StandardCharsets . UTF_8 )) . lines () . collect ( Collectors . joining ( "\n" )) } finally { is . close () } } // print contents of the file from the agent println '===' println ( fileContents ) println '==='
  Jenkins . instance . securityRealm . allUsers . each { user -> println user . id + ": " + user . fullName } import hudson.model.User import jenkins.model.Jenkins User user = User . get ( 'new-user' , true ) user . fullName = "New User" user . save ()
  Jenkins . instance . systemMessage = "New system message" Jenkins . instance . save () println Jenkins . VERSION
  Jenkins . instance . pluginManager . plugins . each { println "${it.shortName}: ${it.version}" } Jenkins . instance . pluginManager . getPlugin ( 'git' ). disable ()
  Jenkins . instance . nodes . each { node -> println "${node.name}: ${node.numExecutors} executors" } Jenkins . instance . getNode ( 'agent-name' ). computer . doDoDelete ()
  try { Jenkins . instance . doSomething () Jenkins . instance . save () println "Operation completed successfully" } catch ( Exception e ) { println "Error: ${e.message}" }
  curl -d "script=<your_script_here>" https://jenkins/script # or to get output as a plain text result (no HTML) curl -d "script=<your_script_here>" https://jenkins/scriptText
  curl --data-urlencode "script= $( < ./somescript.groovy ) " https://jenkins/scriptText
  curl --user 'username:api-token' --data-urlencode \ "script= $( < ./somescript.groovy ) " https://jenkins/scriptText
  with open ( ' somescript.groovy ' , ' r ' ) as fd : data = fd . read () r = requests . post ( ' https://jenkins/scriptText ' , auth = ( ' username ' , ' api-token ' ), data = { ' script ' : data })
  export JENKINS_HOME = "./my_jenkins_home" java -jar jenkins.war