Troubleshoot - Jenkins script in PowerShell (Admin):

Table of Content:

About:

This document shows you how test where the error happens in your Jenkins script. This one can become a bit complicated, but I'm trying my best to explain it. 🥵😄

!! Important !!

This document will give you the general understanding of troubleshooting, but remember that this is something that will be different every single time.

Jenkins 1 - Find the failing Jenkins Repository:

  1. Go to Jenkins and your area in your current company.

  2. Find the repository that fails in Jenkins. Click it.
    !167aa 1.png

  3. Click the last running build.
    !168aa.png

  4. Then click ‘Console Output’.
    !169aa.png


Find the Error Code:

Find the error code:

Scroll down in the code, its usually found near the bottom, but it can also be found further up. Make sure you read the code closely for errors. You should see an error code, or description on why the build failed.

Error Code 1:

  1. In this case, the description isn´t very descriptive. We need to test the script to understand the error.
    !170aa.png

Error Code 2:

  1. In this example there is a slight indicator that there is something wrong in a Jira ticket as it is Expired. Further down we can see that there is something wrong with the Members in this code.
    !171aa.png

Error Code 3:

  1. Here we can see that the name has a special sign in it. This prevents the code from being read correctly.
    !172aa.png

Server 1 - Access The Script:

Do you use Microsoft Remote Desktop?

Learn how to add a server here:
Add Server - Microsoft Remote Desktop

Active Directory Server:

  1. Sign into the correctserver. Open ‘Windows Powershell ISE’. When inside the program, open a new tab by clicking ‘control + n’.
    !173aa.png
    !174aa.png

Jenkins 2 - Access The Script:

  1. Go back to Jenkins, where the error is shown and click the blue link, as the picture show.
    !175aa.png

GitHub 1 - Access The Script:

  1. The link you just clicked should bring you to GitHub, where the code is stored. Click ‘the Repository, then click the code which is recognised by the file extenuation .ps1. The script should now be available to you. Copy it.
    !176aa.png
    !177aa.png
    !178aa.png
    !189aa.png

Server 2 - Troubleshoot

  1. Paste it into the server ‘Windows Powershell ISE’.
    !190aa.png

  2. Run a tiny bit of the script, to locate the error. Keep running small bits of the script, until you hit some red text.

  3. Mark a tiny section of the script by marking it (number 1 -red square), and run it (number 2 -red square).
    !191aa.png

  4. Look for any error messages in the blue text field. In this image there are no error messages.
    !192aa.png

    Example of an error message:

    1. Here you can see an example of an error message in the blue text field.

!193aa.png

  1. We have found the error in the script, but as seen in the screenshot above, it isn't really giving away any issues. Lets dig deeper.

  2. Highlight each variable (number 1 -red square), and run it (number 2 -red square). This will show us what is in each variable, as seen in the screenshots underneaths.
    !194aa.png
    !195aa.png
    Keep doing this until you see something that is off.

  3. In the variable ‘$reporter’ you can see that there is an inconsistent spelling of the reporters name, when compared to the ‘user’ and ‘reporter’. This is what causes the automation in Jenkins to stop working.
    !196aa.png
    !197aa.png

  4. Sometime in the past, the username of Ola Nordmann was spelled incorrectly. When trying to give his user admin access, the script was looking for the aduser with the wrong spelling, which again caused the error. In this specific example, the solution is done in the Server instead of in the script.

Solution to error 2:

Server 3 - Solution:

  1. Go to Server as the admin user again, and add the computer name in the 'Description field' (with a comma behind) like the screenshot shows. This works because the script has a workaround in case username errors like this, as it has happened in the past.
    !198aa.png
  2. The script and Jenkins will now run as it should indicated by the green checkmark.
    !199aa.png

And you are done. 😄