SonarQube scan Angular in Jenkins

Prerequisites

  1. Install SonarQube Scanner Plugin
  2. Configure the SonarQube instance in Jenkins

Freestyle

  1. Navigate to Build section of your project
  2. Click Add Build Step
  3. Add_Build_Step_2019-02-14_11-11-27
  4. Select Execute SonarQube Scanner
  5. Execute_SonarQube_Scanner_2019-02-14_11-13-25
  6. Select your SonarQube Installation
  7. Set scanas the task to run
  8. Set the path to your sonar-project.properties file
  9. Configure_Build_Step_2019-02-14_11-24-55
  10. My file looked like this

Aside

I recommend using the sonar-project.properties file rather than the Jenkins UI. It allows you to keep it in source control. Having the properties separate makes the move to other CI/CD systems in the future easier as well.

References

  1. Angular Fitbit = Jenkins + SonarQube
  2. Analyzing with SonarQube Scanner for Jenkins
Advertisements

Mulesoft AnyPoint Studio Setup Scripted

Problem

You’re all excited to get started using Anypoint Studio 7. Then this little monster rears it’s ugly head.

JDK_Must_Be_Installed_2019-03-28_16-28-06

Solution

    1. Save the below to a file named Mulesoft_Setup.ps1
    2. You will need to modify $javaDir to be your java install directory
    3. You will need to modify $anypointStudioDir to be your Anypoint Studio 7 install directory
    4. Run it with powershell -ExecutionPolicy ByPass -File Mulesoft_Setup.ps1
      1. There are other ways to set the execution policy, but I prefer to set it for a single command rather than system wide.
    5. Then you should be able to run Anypoint Studio 7

References

  1. Mulesoft Community: JDK must be installed in order to run Anypoint Studio
  2. Mulesoft Community: Unable to install Mule 4 anypoint studio 7.1 ?
  3. YouTube: How To – Install Java JDK on Windows 10 ( With JAVA_HOME )
  4. StackOverflow:PowerShell and the -contains operator
  5. StackOverflow: Do I need to restart my system after setting JAVA in system environment’s path variable?
  6. MPC Mag: How To Replace Text in a File with PowerShell
  7. StackOverflow: Is there a PowerShell “string does not contain” cmdlet or syntax?

Bitbucket Can’t Diff SQL Files

Problem

I ran into this issue trying to compare ANSI and UTF-8 sql files with Atlassian BitBucket. You receive a screen that tells you to download the files and compare them locally.

can't_diff_redacted_2019-01-24_13-24-29

This is a pretty brutal workflow and I’m not the first person to encounter this issue.  Fortunately, there is a better way.

Solution

I resolved this by doing the following steps.

  1. Verify that you have Admin access to the repository
  2. Open your repository
  3. Click the Gear for Settings
  4. Check the Transcode diffs checkbox like in the screenshot below
  5. bitbucket_transcode_diffs_2019-01-24_11-55-48
  6. Then you’ll be able to diff your sql files within Atlassian BitBucket like the screenshot below
  7. working_diff_2019-01-24_13-45-04

 

 

Jenkins: Keep Secrets Secret

Problem

It’s often helpful to use Jenkins to manage secrets (i.e. passwords, api keys, credentials, etc.). This post explains how to go about doing just that for Jenkins pipelines.

Solution

  1. Install the Credentials Binding Plugin on your Jenkins instance in https://my.instance.com/pluginManager/available
  2. Add the following code to the appropriate place in your pipeline
  1. The above example shows applying this technique to pushing NuGet packages. However the same pattern could be applied were any secrets are used.

References

  1. cloud bees: Fetch a userid and password from a Credential object in a Pipeline job.
  2. Jenkins Credentials binding plugin documentation
  3. Jenkins Credentials binding plugin page

 

Artillery: Capture Response Data

Problem

You need to call an API and use data that is sent back in the response. This could be for authentication or creating complex testing scenarios.

Solution

  1. Verify that Artillery is installed and working.
  2. Create your .yml file
  3. Add the below configuration to it
  4. It will store the value from the response $.access_token, in this case 42, into the $token variable for later use
  5. This example assumes the response looks something like the one below

Here is what the final .yml file might look like

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

 

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