Skip to content
Permalink
master
Switch branches/tags
Go to file
 
 
Cannot retrieve contributors at this time
trigger:
branches:
include:
- master
variables:
# Agent VM image name
vmImageName: "jldeenlinux"
# artifactory URL
artDocker_URL: "jfrogjd-docker.jfrog.io"
# artifactory USER
ART_USER: "admin"
# artifactory server-id
server-id: "jfrog-jd"
# art url
ART_URL: "https://jfrogjd.jfrog.io/jfrogjd"
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
# name: work-machine
name: $(vmImageName)
steps:
- bash: |
#Login to Docker with jfrog artifactory creds
echo $(ART_PASS) | docker login $(artDocker_URL) -u $(ART_USER) --password-stdin && echo "jfrog docker login successful"
# Get Jfrog CLI
if [ -e jfrog ]; then
echo "Jfrog binary already exists. Logging into Artifactory now.."
else
echo "Jfrog binary does not exist. Downloading now...."
curl -fL https://getcli.jfrog.io | sh
sudo mv jfrog /usr/local/bin
fi
# Configure Jfrog CLI
jfrog rt config $(server-id) --url=$(ART_URL) --user=$(ART_USER) --password=$(ART_PASS) --interactive=false
displayName: "jfrog install, configure cli"
- bash: |
# --- jfrog Maven Build
export M2_HOME=/usr/share/maven
jfrog rt mvn "clean install -U -Dproject.version=$(Build.BuildId) -Dartifactory.publish.buildInfo=true" --build-name=$(System.TeamProject) --build-number=$(Build.BuildId)
# jfrog rt build-collect-env $(System.TeamProject) $(Build.BuildId)
# jfrog rt build-publish $(System.TeamProject) $(Build.BuildId)
displayName: "jfrog maven build"
- task: Docker@2
displayName: buildAndPush
inputs:
containerRegistry: "Jfrog Artifactory"
repository: "$(Build.Repository.Name)"
command: "buildAndPush"
Dockerfile: "Dockerfile"
buildContext: "."
- task: HelmInstaller@1
displayName: Install Helm 3.1.0 Client Binary
inputs:
helmVersionToInstall: "3.1.0"
- task: KubectlInstaller@0
displayName: Install Kubectl 1.17.1 Tool
inputs:
kubectlVersion: "1.17.1"
- bash: helm lint charts/spring-boot-websocket-chat-demo
displayName: helm lint
- task: HelmDeploy@0
displayName: "helm package"
inputs:
command: "package"
chartPath: "charts/spring-boot-websocket-chat-demo"
save: false
- bash: |
# --- Jfrog Docker Push
jfrog rt docker-push --server-id=$(server-id) --build-name=$(System.TeamProject) --build-number=$(Build.BuildId) "$(artDocker_URL)/$(Build.Repository.Name):$(Build.BuildId)" docker-dev
# --- Upload Helm Chart Artifact to Artifactory
jfrog rt upload --server-id=$(server-id) --build-name=$(System.TeamProject) --build-number=$(Build.BuildId) "$(Build.ArtifactStagingDirectory)/*.tgz" helm-repo
# --- JFrog Collect Build Info to Artifactory
jfrog rt build-collect-env $(System.TeamProject) $(Build.BuildId)
jfrog rt build-add-git $(System.TeamProject) $(Build.BuildId)
# -- build publish
jfrog rt build-publish --build-url="https://dev.azure.com/$(System.CollectionId)/$(System.TeamProject)/_build/$(Build.BuildId)" --env-exclude="*key*;*pass*;" $(System.TeamProject) $(Build.BuildId) |& tee publish.txt
# --- Xray Scan
jfrog rt build-scan --server-id=$(server-id) $(System.TeamProject) $(Build.BuildId) | tee results.json
displayName: "jfrog publish build info to artifactory"
- bash: |
## Jfrog Build
JF_BUILD=$(sed -n "s/^.*http/http/p" publish.txt)
curl -X POST --data-urlencode 'payload={"text":"Jfrog Artifactory Azure DevOps Build '$(Build.BuildId)' Information","attachments":[{"fallback":"JFrog Artifactory Azure DevOps Build '$(Build.BuildId)' Information","color":"#36a64f","author_link":"'$JF_BUILD'","title":"JFrog Build Artifacts","title_link":"'$JF_BUILD'","text":"Build Artifacts for Azure DevOps '$(Build.BuildId)'","fields":[{"title":"Requested for","value":"Jessica Deen","short":false}],"footer":"JFrog Artifactory Notifications","footer_icon":"https:\/\/www.clipartmax.com\/png\/middle\/69-698347_jfrog-artifactory-logo.png"}]}' $(SLACK_WEBHOOK_URL) && echo "Slack Build Message Posted" && echo "Slack Build Message Posted"
displayName: "Slack Build Trigger"
- bash: |
## Jfrog Xray Scan
JF_XRAY_ALERTS=$(jq ".summary.total_alerts" results.json)
JF_SCAN_FAIL=$(jq ".summary.fail_build" results.json)
JF_XRAY_RPT="https://jfrogjd-xray.jfrog.io/web/#/component/details/build:~2F~2Fchattybot2020/$(Build.BuildId)"
if [[ $JF_XRAY_ALERTS -eq 0 ]]; then
slackStyle=good && echo "No Xray Scan alerts found"
else
slackStyle=danger && echo "Xray scan alerts found"
fi
curl -X POST --data-urlencode 'payload={"text":"JFrog XRay Scan Report for Azure DevOps Build '$(Build.BuildId)'","attachments":[{"fallback":"JFrog XRay Scan Report for Azure DevOps Build '$(Build.BuildId)'","color":"'$slackStyle'","author_link":"'$JF_XRAY_RPT'","title":"JFrog XRay Scan Report for Azure DevOps","title_link":"'$JF_XRAY_RPT'","text":"JFrog Xray Scan Report for Azure DevOps Build '$(Build.BuildId)'","fields":[{"title":"XRay Alerts","value":"'$JF_XRAY_ALERTS' alerts were generated","short":false},{"title":"Requested for","value":"Jessica Deen","short":false}],"footer":"JFrog XRay Scan Notifications","footer_icon":"https:\/\/www.clipartmax.com\/png\/middle\/69-698347_jfrog-artifactory-logo.png"}]}' $(SLACK_WEBHOOK_URL) > /dev/null 2>&1 && echo "Slack XRay Message Posted"
if [[ "'$JF_SCAN_FAIL'" = *true* ]]; then exit 1; else exit 0; fi
displayName: "Slack Xray Trigger"
- stage: DeployToDev
displayName: Deploy to Dev
dependsOn: Build
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/heads/'))
jobs:
- deployment: Deploy
displayName: Deploy job
pool:
# name: work-machine
name: jldeenlinux
environment: "chattybot-dev"
strategy:
runOnce:
deploy:
steps:
- bash: |
## Jfrog Download Helm Chart
jfrog rt download --server-id=$(server-id) --build-name=$(System.TeamProject) --build-number=$(Build.BuildId) "helm-repo/*.tgz" $(System.ArtifactsDirectory)/charts/
displayName: Download Helm Chart Artifact
- bash: 'ls -la $(System.ArtifactsDirectory)/charts && echo "$(System.ArtifactsDirectory)"'
displayName: "Check pipeline artifacts"
- task: HelmInstaller@0
displayName: "Install Helm 3.1.1"
inputs:
helmVersion: "3.1.0"
checkLatestHelmVersion: false
installKubectl: true
kubectlVersion: "1.17.1"
- task: HelmDeploy@0
inputs:
connectionType: "Azure Resource Manager"
azureSubscription: "ca-jessde-demo-test(1)(dfb5d696-98d8-447c-a14d-56f131f3c4a5)"
azureResourceGroup: "jdk8s"
kubernetesCluster: "jdk8saks3qpc7haiwjlfa"
namespace: "jfrog"
command: "upgrade"
chartType: "FilePath"
chartPath: "$(System.ArtifactsDirectory)/charts/spring-boot-websocket-chat-demo-v0.1.0.tgz"
releaseName: "azdspring-dev"
overrideValues: "image.repository=jfrogjd-docker.jfrog.io/jldeen/spring-boot-websocket-chat-demo,image.tag=$(Build.BuildId),ingress.hostname=azdspring20-dev.k8s.az.jessicadeen.com,buildID=$(Build.BuildId)"
- stage: PromoteToProd
displayName: Promote to Prod
dependsOn: DeployToDev
condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/heads/'))
jobs:
- deployment: Deploy
displayName: Promote to Prod
pool:
# name: work-machine
name: jldeenlinux
environment: "chattybot-prod"
strategy:
runOnce:
deploy:
steps:
- bash: |
## Jfrog Download Helm Chart
jfrog rt download --server-id=$(server-id) --build-name=$(System.TeamProject) --build-number=$(Build.BuildId) "helm-repo/*.tgz" $(System.ArtifactsDirectory)/charts/
displayName: Download Helm Chart Artifact
- bash: 'ls -la $(System.ArtifactsDirectory)/charts && echo "$(System.ArtifactsDirectory)"'
displayName: "Check pipeline artifacts"
- task: HelmInstaller@1
inputs:
helmVersionToInstall: "3.1.0"
- task: KubectlInstaller@0
inputs:
kubectlVersion: "1.17.1"
- task: HelmDeploy@0
inputs:
connectionType: "Azure Resource Manager"
azureSubscription: "ca-jessde-demo-test(1)(dfb5d696-98d8-447c-a14d-56f131f3c4a5)"
azureResourceGroup: "jdk8s"
kubernetesCluster: "jdk8saks3qpc7haiwjlfa"
namespace: "jfrog-prod"
command: "upgrade"
chartType: "FilePath"
chartPath: "$(System.ArtifactsDirectory)/charts/spring-boot-websocket-chat-demo-v0.1.0.tgz"
releaseName: "azdspring-prod"
overrideValues: "image.repository=jfrogjd-docker.jfrog.io/jldeen/spring-boot-websocket-chat-demo,image.tag=$(Build.BuildId),replicaCount=1,ingress.hostname=azdspring20.k8s.az.jessicadeen.com,buildID=$(Build.BuildId)"