RabbitMQ User Gotcha

Problem

By default, it looks at your %appdata% (e.g. C:\Users\User\AppData\Roaming) for reading configuration files and writing to logs.

This caused a log of confusion for me since I have to use a separate account to get local admin access for security reasons.

Solution

The two below approaches allow you to verify you are editing configuration in the correct directories.

Using the web admin

  1. Install the management plugin with the command
    1. rabbitmq-plugins enable rabbitmq_management
  2. Go to http://{node-hostname}:15672/
  3. Navigate to the Nodes section similar to the screenshot below
  4. RabbitMQ_Nodes_2018-12-31_1-21-12
  5. Click on the desired node
  6. You should see the following values and their paths
    1. Config file
    2. Database directory
    3. Log file
    4. SASL log file
  7. It should look like the below screenshot
  8. RabbitMQ_Overview_2018-12-31_1-05-16

Using the RabbitMQ console

    1. Open the RabbitMQ Command Prompt
    2. Or navigate to the sbin folder (by default in C:\Program Files\RabbitMQ Server\rabbitmq_server-{version}\sbin)
    3. You can view the variable values for the running environment with the command
      1. rabbitmqctl environment
    4. You’ll see output similar to the one below
    5. RabbitMQ_Check_Environment_2018-12-31_11-13-44

 

Advertisements

Jenkins Publish xUnit Results

Prerequisites

  1. Install the Jenkins xUnit Plugin
  2. Run xUnit Tests on Jenkins

Steps

For a Jenkins Pipeline

  1. Add the below snippet to the appropriate stage in your pipeline
  2. step([$class: 'XUnitBuilder', thresholds: [[$class: 'FailedThreshold', unstableThreshold: '1']], tools: [[$class: 'XUnitDotNetTestType', pattern: '*results.xml']]])
  3. You may have to update the pattern depending upon how you specified the output file when you ran the xunit tests.

For a freestyle project

  1. Go to Post-Build Actions
  2. Click Add Post-Build Action
  3. Click Add next to Report Type
  4. Select xUnit.Net-v2(default)
  5. Set the patern to be test_results.xml
  6. Configure any other options as necessary

References

  1. Publish Xunit result in Jenkins pipeline
  2. Jenkins xUnit Plugin
  3. Cloud Bees: xUnit and Pipeline
  4. Test Results Analyzer Jenkins Plugin

Jenkins Publish NUnit Results

Prerequisites

  1. Install the NUnit plugin
  2. Have running NUnit tests exporting results

Steps

For a Pipeline project

  1. Add the below snippet to the appropriate place in your pipeline
  2. step([$class: 'NUnitPublisher', testResultsPattern: '*.xml', debug: false, keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])
  3. You may have to update the testResultsPattern or other options to suit your environment

For a Freestyle project

  1. Go to the Post-build Actions
  2. Click Add Post-build Action 
  3. Select Publish NUnit test result report
  4. Copy TestResult.xml into the Test report XMLs textbox

References

  1. NUnit Jenkins Plugin
  2. StackOverflow Publishing NUnit for Pipeline

Jenkins Run xUnit Tests

Problem

You’ve worked hard creating unit tests using xUnit. That’s a great start. This doesn’t mean you’re finished though.

  1. How do you know that the tests are being run?

Solution

Running the tests

Jenkins makes this part easy. There are two different types of builds that you can choose from. I’ll share how to do run unit tests with xUnit for both types. I am assuming the build will run on a windows node or master.

For a Pipeline Project

  1. Add the following code snippet to the appropriate stage in your pipeline
  2. bat "packages\\xunit.runner.console.2.4.1\\tools\\net452\\xunit.console.exe my_project.Tests\\bin\\Release\\my_project.Tests.dll -xml test_results.xml"
  3. You may have to modify the path depending on your project configuration
  4. I reference the console executable from packages to reduce dependencies and make the project portable.

For a Freestyle Project

  1. Add a “Execute Windows batch command” build step
  2. Add the following command packages\\xunit.runner.console.2.4.1\\tools\\net452\\xunit.console.exe my_project.Tests\\bin\\Release\\my_project.Tests.dll -xml test_results.xml
  3. You may have to modify the path depending on your project configuration
  4. I reference the console executable from packages to reduce dependencies and make the project portable.
  5. The end result should look like this

RabbitMQ: Remove Windows Node

Purpose

Remove an existing RabbitMQ on a windows server from a clusterqrv

Prerequisiten

  1. Follow my Install Guide or another install guide
  2. Have the node working in a RabbitMQ clusterl

Local Instructions

  1. Login to the node
  2. Run these commands from the RabbitMQ Command prompt
  3. Run rabbitmqctl stop_app
  4. Run rabbitmqctl reset

Remote Instructions

  1. Run these commands from the RabbitMQ Command prompt
  2. Run rabbitmqctl stop_app on the node to be removed
  3. Run rabbitmqctl -n rabbit@node1 forget_cluster_node rabbit@node2
    1. This will remove the rabbit@node2 from the cluster by executing the removal from node1

Resources

  1. CodingInsomnia: Clustering RabbitMQ on Windows
  2. How to determine if a port is open on a Windows server?
  3. In Windows, using the command line, how do you check if a remote port is open?
  4. RabbitMQ Erlang Version Requirements
  5. RabbitMQ: Management Plugin
  6. RabbitMQ: Forget Cluster Node

HashiCorp Vault Consumer Authenticate

Problem

I haven’t been able to find a lot of resources on consuming HashiCorp Vault. You need to authenticate to access your secrets stored in Vault.

Solution

The below code assumes that you have the

  1. url for the Hashicorp Vault api
  2. app-id and user-id created within Hashicorp Vault

It’s recommended to url encode the app-id since it will be added to the url to avoid cross-site scripting(XSS).

The serialized body will provide you with the token needed for subsequent calls to retrieve secrets stored in Hashicorp Vault.

Create Certificate Request in IIS

Problem

You need to create a certificate request to get a get a certificate from Microsoft Active Directory Certificate Services.

Assumptions

  1. Running on Windows
  2. Using IIS

Solution

    1. Go to the server where the certificate will be used
    2. Open IIS
    3. Click Server Certificates

IIS_Server_Certificates_2018-06-29_10-48-42

    1. Click Create Server Request

IIS_Create_Certificate_Request_2018-06-29_10-56-49

  1.  Fill out the information
  2. The Common Name(CN) must match the url or host name to work.
  3. Click Next

IIS_Certificate_Request_Distinguished_Name_Properties_2018-06-29_11-02-25

  1. Choose your Cryptographic Service Provider
  2. Choose your bit length
  3. Click Next

Request_Certificate_Cryptographic_Service_Provider_2018-06-29_11-10-27

  1. Choose the filename where the request should be stored
  2. Click Finish

Request_Certificate_Filename_2018-06-29_13-22-57

Now you have your certificate request ready to upload to Microsoft Active Directory Certificate Services.

SQL Server Check Backups

Problem

It’s easy to assume that backups are happening on you SQL Server DBs. But assuming can be dangerous! It’s nice to know backups are created and when the last one was. Yet asking your DBA’s when the most recent backup was taken isn’t the most engaging question. That conversation would be better spent talking about how your teams can work together.

Solution

  1. Open SQL Server Management Studio
  2. Connect to your SQL Server
  3. Click View
  4. Click Object Explorer Details
  5. SQL_Server_Management_Studio_Object_Explorer_Details_2018-10-06_22-54-09
  6. In the Object Explorer, Select the database you’re interested in
  7. On the right after you scroll, you’ll see a line stating Last Backup Date
  8. SQL_Server_Management_Studio_Last_Backup_Date_2018-10-06_22-56-38
  9. Now you can check the Last Backup Date on your own!

Moving Jenkins Home

Problem

Jenkins and building software tends to generate a lot of files. If you used the default install directory for windows, those files went to C:\Program Files (x86)\Jenkins . This is all well and good until the C drive starts running out of space. We can move the Jenkins HOME directory.

Solution

          1. Backup using ThinBackup
          2. Stop Jenkins service
          3. Stop_Jenkins_Service_2018-10-05_15-10-19
          4. Create new directory (e.g. E:\Jenkins)
          5. Copy existing folder(by default C:\Program Files (x86)\Jenkins) to the new directory
          6. Diff the original and new to see if it worked
          7. Uninstall Jenkins service using jenkins.exe uninstall
          8. Open System Properties -> Advanced Tab
          9. System_Properties_Environment_Variables_2018-10-05_15-14-53
          10. Click Environment Variables...
          11. set JENKINS_HOME environment variable system wide
          12. Set_Jenkins_Home_2018-10-05_15-13-08
          13. Log out
          14. Log back in
          15. Verify that the environment variable was set with set | find "JENKINS_HOME"
          16. Confirming_Jenkins_HOME_Environment_Variable_2018-10-07_2-18-40
          17. Re-install the Jenkins windows service with jenkins.exe install
          18. Start the Jenkins service

     

References

  1. StackOverflow: Relocating JENKINS_HOME on Windows when installed as service

Jenkins Run NUnit Tests

Problem

You’ve worked hard creating unit tests using NUnit. That’s a great start. This doesn’t mean you’re finished though.

  1. How do you know that the tests are being run?

Solution

Running the tests

Jenkins makes this part easy. There are two different types of builds that you can choose from. I’ll share how to do run unit tests with NUnit for both types.

Below you can see how it is configured in a FreeStyle Project. I am assuming the build will run on a Windows node or master.

Nunit_Test_Run_Freestyle_Build_2018-06-06_13-05-55

Below you can see how it is configured in a Pipeline Project. I am assuming the build will run on a Windows node or master.

Aside: I used the NUnit.ConsoleRunner package explicitly rather than depending on the Jenkins node to have this dependency. If the version is updated, this will break. However it makes it easier to scale Jenkins nodes horizontally.

Aside: I highly recommend using the NUnit Test Adapter if you are using .NET to simplify your setup.