Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Image Removed

After this step, the scans automatically upload to Black Duck.

Redirect

...

Automating the Jenkins build enables an automated application build when changes occur in your source code repository.  When Jenkins detects source code changes, the application is automatically built and scanned using the Black Duck Docker scan client.

...

  1. In Jenkins, click Manage Jenkins > Configure System > Credentials > Global Credentials (Unrestricted) > Add Credentials.
  2. Select:
    1. Kind as Username with Password.
    2. Scope as Global.
    3. Provide your GitHub credentials.
    4. Click OK.

Image Removed

Setting the Black Duck password in the Jenkins environment variable

Add the environment variable BD_HUB_PASSWORD in Manage Jenkins > Configure System > Global properties.

Image Removed

Creating the project in Jenkins

Source Code Management

For this example, configure the GIT repository as follows:

  1. Provide the GIT Repository URL.
  2. Select the Credentials.
  3. Add branches to the Branches to build field.

Image Removed

Build triggers

In this build triggers example, the GIT repository is polled every five minutes to detect changes.

Image Removed

Build environment

Changes detected in the source code triggers the build. Add the following steps in Build > Add Build Step > Execute Shell:

  1. Set the GCloud project.
  2. Set the image tag.
  3. Set the Black Duck URL (Hub versions 4.1.0 and higher).
  4. Set the Black Duck scheme.
  5. Build the image for the modified code.
  6. Download the Black Duck Docker scan client, based on your operating system.
  7. Scan the built image using the downloaded Black Duck Docker scan client.
  8. Remove the downloaded Black Duck Docker scan client.
  9. Push the built image to Google cloud.
  10. Remove the local image.
Code Block
themeRDark
#!/bin/bash
set -e

# Set current project
PROJECT_ID=eng-dev

# Set the latest image tag
IMAGE_TAG=us.gcr.io/${PROJECT_ID}/redmine:${GIT_BRANCH#*/}-${GIT_COMMIT:0:7}

# Set the Hub Url
HUB_URL=bizdevhub.blackducksoftware.com

# Set the Hub Scheme
HUB_SCHEME=https

# Build image
echo "Docker build started"
docker build -t $IMAGE_TAG .
echo "Docker build completed"

# Download the BlackDuck Hub scan client based on the OS and unzip it
case "$OSTYPE" in
darwin*) curl -LOk $HUB_SCHEME://$HUB_URL/download/scan.cli-macosx.zip ;;
linux*) curl -LOk $HUB_SCHEME://$HUB_URL/download/scan.cli.zip ;;
msys*) curl -LOk $HUB_SCHEME://$HUB_URL/download/scan.cli-windows.zip ;;
*) echo "BlackDuck Scan client is unavailable for : $OSTYPE" ;;
esac

echo "Scan client download completed"
unzip scan.cli*.zip
echo "Scan client unzip done"

# Call the BlackDuck Hub scan docker script
cd scan.cli-*/bin
echo "change directory done"
./scan.docker.sh --image $IMAGE_TAG --host $HUB_URL --username sysadmin --scheme $HUB_SCHEME --use-local
echo "Scan completed"

# remove zip file and folder
cd ../..
rm -rf scan.cli-*
echo "Removed the client files"

# Push image
gcloud docker -- push $IMAGE_TAG
echo "GCloud docker push completed"

# Remove the local image
docker rmi $IMAGE_TAG
echo "Removed local docker image"

delay3
filename
locationhttps://sig-product-docs.synopsys.com/bundle/Black_Duck_Jenkins_integration_with_Google_Container_Engine(GKE)/resource/Black_Duck_Jenkins_integration_with_Google_Container_Engine(GKE).pdf