Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
fix spacing 59cf1c6 Jun 18, 2019
1 contributor

Users who have contributed to this file

257 lines (227 sloc) 10.7 KB
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'
# slack channel
slackChannel: 'chattybot'
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...."
wget https:// dl.bintray.com/jfrog/jfrog-cli-go/1.24.2/jfrog-cli-linux-amd64/jfrog
chmod +x jfrog
fi
# Configure Jfrog CLI
./jfrog rt config $(server-id) --url=$(ART_URL) --user=$(ART_USER) --password=$(ART_PASS)
displayName: 'jfrog install, configure cli'
- bash: |
# --- jfrog Maven Build
export M2_HOME=/usr/share/maven
./jfrog rt mvn "clean install -Dproject.version=$(Build.BuildId) -Dartifactory.publish.buildInfo=true" maven.yaml --build-name=$(System.TeamProject) --build-number=$(Build.BuildId)
displayName: 'jfrog maven build'
- task: Docker@2
displayName: buildAndPush
inputs:
containerRegistry: 'Jfrog Artifactory'
repository: '$(Build.Repository.Name)'
- task: HelmInstaller@0
displayName: 'Install Helm 2.14.1'
inputs:
helmVersion: 2.14.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'
- bash: |
# --- JFrog Publish Build Info to Artifactory
#./jfrog rt build-add-dependencies $(System.TeamProject) $(Build.BuildId) "target/*.jar"
./jfrog rt build-collect-env $(System.TeamProject) $(Build.BuildId)
./jfrog rt build-add-git $(System.TeamProject) $(Build.BuildId)
# --- 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
# -- 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 https://slack.com/api/chat.postMessage -H 'Accept: */*' -H 'Authorization: Bearer $(slackBotToken)' -H 'Connection: keep-alive' -H 'Content-Type: application/json; charset=utf-8' -H 'accept-encoding: gzip, deflate' -d '{"channel": "$(slackChannel)", "text": "Jfrog Artifactory Build $(Build.BuildId) Information", "attachments": [
{
"fallback": "JFrog Artifactory Build $(Build.BuildID) Information",
"color": "#36a64f",
"author_link": "'$JF_BUILD'",
"title": "JFrog Build Artifacts",
"title_link": "'$JF_BUILD'",
"text": "Build Artifacts for $(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"
}
]
}' && 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/docker:~2F~2Fjldeen~2Fspring-boot-websocket-chat-demo/$(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 https://slack.com/api/chat.postMessage -H 'Accept: */*' -H 'Authorization: Bearer $(slackBotToken)' -H 'Connection: keep-alive' -H 'Content-Type: application/json; charset=utf-8' -H 'accept-encoding: gzip, deflate' -d '{"channel": "$(slackChannel)", "text": "JFrog XRay Scan Report for Build $(Build.BuildID)", "attachments": [
{
"fallback": "JFrog XRay Scan Report for Build $(Build.BuildID)",
"color": "'$slackStyle'",
"author_link": "'$JF_XRAY_RPT'",
"title": "JFrog XRay Scan Report",
"title_link": "'$JF_XRAY_RPT'",
"text": "JFrog Xray Scan Report for 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"
}
]
}' && 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
inputs:
helmVersion: '2.14.0'
- task: HelmDeploy@0
displayName: 'helm init'
inputs:
azureSubscription: 'ca-jessde-demo-test(dfb5d696-98d8-447c-a14d-56f131f3c4a5)'
azureResourceGroup: 'jdk8s-us'
kubernetesCluster: 'jdk8s-us'
command: init
upgradeTiller: false
arguments: '--client-only'
- task: HelmDeploy@0
displayName: 'helm upgrade'
inputs:
azureSubscription: 'ca-jessde-demo-test(dfb5d696-98d8-447c-a14d-56f131f3c4a5)'
azureResourceGroup: 'jdk8s-us'
kubernetesCluster: 'jdk8s-us'
command: upgrade
chartType: FilePath
chartPath: '$(System.ArtifactsDirectory)/charts/spring-boot-websocket-chat-demo-v0.1.0.tgz'
releaseName: 'swampup19-dev'
namespace: 'jfrog'
overrideValues: 'image.repository=jfrogjd-docker.jfrog.io/jldeen/spring-boot-websocket-chat-demo,image.tag=$(Build.BuildId),ingress.hostname=dev-swampup19.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@0
inputs:
helmVersion: '2.14.0'
- task: HelmDeploy@0
displayName: 'helm init'
inputs:
azureSubscription: 'ca-jessde-demo-test(dfb5d696-98d8-447c-a14d-56f131f3c4a5)'
azureResourceGroup: 'jdk8s-us'
kubernetesCluster: 'jdk8s-us'
command: init
upgradeTiller: false
arguments: '--client-only'
- task: HelmDeploy@0
displayName: 'helm upgrade'
inputs:
azureSubscription: 'ca-jessde-demo-test(dfb5d696-98d8-447c-a14d-56f131f3c4a5)'
azureResourceGroup: 'jdk8s-us'
kubernetesCluster: 'jdk8s-us'
command: upgrade
chartType: FilePath
chartPath: '$(System.ArtifactsDirectory)/charts/spring-boot-websocket-chat-demo-v0.1.0.tgz'
releaseName: 'swampup19-prod'
namespace: 'jfrog-prod'
overrideValues: 'image.repository=jfrogjd-docker.jfrog.io/jldeen/spring-boot-websocket-chat-demo,image.tag=$(Build.BuildId),buildID=$(Build.BuildId)'
You can’t perform that action at this time.