Skip to content

Commit

Permalink
migrate jenkinsfile
Browse files Browse the repository at this point in the history
  • Loading branch information
szczepaniak_p committed Mar 4, 2021
1 parent 637387c commit b4cad75
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 177 deletions.
151 changes: 47 additions & 104 deletions .jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,137 +1,80 @@

pipeline {
agent {
kubernetes {
label 'mono3'
inheritFrom 'mono3'
defaultContainer 'default'
defaultContainer 'mono3'
}
}
triggers{
bitbucketPush()
}
options{
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
}
buildDiscarder(logRotator(numToKeepStr: '3'))
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds() }
parameters {
booleanParam(defaultValue: true, description: '', name: 'DIAGNOSTIC_FLAG')
booleanParam(defaultValue: false, description: '', name: 'CAN_RELEASE')
}
environment {
CI = 'true'
}
booleanParam(defaultValue: true, description: 'verbose mode', name: 'DIAGNOSTIC_FLAG')
booleanParam(defaultValue: false, description: 'branch ready to release', name: 'CAN_RELEASE')
string(defaultValue: 'feature/MTM-37209/test-build-branch', description: 'specific build/release branch name', name: 'branch_name', trim: true)
}
environment { DIAGNOSTIC_FLAG_ENV = "${params.DIAGNOSTIC_FLAG ? '-verbosity=diagnostic' : ''}" }
stages {
stage('Build') {

when {
stage('Checkout') {
steps {
container('mono3') {
checkout([
$class: 'GitSCM', branches: [[name: params.branch_name]],
extensions: [[$class: 'CleanCheckout']],
userRemoteConfigs: [[url: 'git@bitbucket.org:m2m/cumulocity-clients-cs.git',credentialsId:'jenkins-master']] ]) }
}
}
stage('Build') {
when {
anyOf{
branch 'develop'
branch 'feature/**'
}
}
steps {

script {
if ("${params.CAN_RELEASE}" == "true" && env.BRANCH_NAME == "develop") {
echo "CAN_RELEASE: ${params.CAN_RELEASE}"

sshagent (['jenkins-master-key']) {
sh '''#!/bin/bash
whoami
chmod +x ./MicroservicesSDK/build.sh
cd MicroservicesSDK
pwd
./build.sh --script build-release.cake
'''
}
}
else{
if ("${params.DIAGNOSTIC_FLAG}" == "true") {
echo "diagnostic flag: ${params.DIAGNOSTIC_FLAG}"
sh 'cd MicroservicesSDK && chmod +x ./build.sh && pwd && ./build.sh -target=Test -verbosity=diagnostic'
}else
{
echo "diagnostic flag: ${params.DIAGNOSTIC_FLAG}"
sh 'cd MicroservicesSDK && chmod +x ./build.sh && pwd && ./build.sh -target=Test'
}
}
container('mono3') {
script {
echo "diagnostic flag: ${params.DIAGNOSTIC_FLAG}"
sh 'cd MicroservicesSDK && chmod +x ./build.sh && ./build.sh -target=Test ${DIAGNOSTIC_FLAG_ENV} && cd .. '
}
}
}
}
}
stage('Deliver for development') {
when {
branch 'development'
}
steps {
sh 'echo DevelopmentBranch'
}
}
}
stage('Release') {
when {
branch "release/*"
anyOf{
branch 'develop'
branch "release/*"
}
}
steps {
script {
if ("${params.DIAGNOSTIC_FLAG}" == "true" && ("${params.CAN_RELEASE}" == "true")) {
sh 'echo Release Branch'
echo "diagnostic flag: ${params.DIAGNOSTIC_FLAG}"

echo "Release Branch"

sshagent (['jenkins-master-key']) {
sh '''#!/bin/bash
whoami
chmod +x ./MicroservicesSDK/build.sh
cd MicroservicesSDK
pwd
./build.sh --script build-release.cake -verbosity=diagnostic
'''
}

}else if ("${params.CAN_RELEASE}" == "true")
{
echo "Release Branch"

sshagent (['jenkins-master-key']) {
sh '''#!/bin/bash
whoami
chmod +x ./MicroservicesSDK/build.sh
cd MicroservicesSDK
pwd
./build.sh --script build-release.cake
'''
}
} else {
sh 'echo Release Branch'
echo "CAN_RELEASE: ${params.CAN_RELEASE}"
}
container('mono3') {
script {
echo "CAN_RELEASE: ${params.CAN_RELEASE}"
echo "diagnostic flag: ${params.DIAGNOSTIC_FLAG}"
if ("${params.CAN_RELEASE}" == "true") {
sshagent (['jenkins-master']) {
sh 'cd MicroservicesSDK && chmod +x ./build.sh && ./build.sh --script build-release.cake ${DIAGNOSTIC_FLAG_ENV}'
}
}
}
}
}
}
}
}
}
}

post {
success{

withCredentials([usernamePassword(credentialsId: 'bitbucket-m2m', passwordVariable: 'BITBUCKET_PASSWORD', usernameVariable: 'BITBUCKET_USER')]) {
sh "chmod +x .jenkins/scripts/status.sh && .jenkins/scripts/status.sh 'SUCCESSFUL' ${JOB_NAME} ${BUILD_TAG} "
}
}
failure {
script {
if (env.BRANCH_NAME ==~ '(develop|release/.*)') {
chat 'AAAAvnc5o90'
// chat 'AAAAvnc5o90'
}
}

withCredentials([usernamePassword(credentialsId: 'bitbucket-m2m', passwordVariable: 'BITBUCKET_PASSWORD', usernameVariable: 'BITBUCKET_USER')]) {
sh "chmod +x .jenkins/scripts/status.sh && .jenkins/scripts/status.sh 'FAILED' ${JOB_NAME} ${BUILD_TAG} "
}
}
cleanup {
echo 'One way or another, I have finished.'
deleteDir() /* clean up our workspace */
}
}
}
}
29 changes: 0 additions & 29 deletions .jenkins/build_only.Jenkinsfile

This file was deleted.

48 changes: 4 additions & 44 deletions MicroservicesSDK/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,16 @@
deploy() {

YUM_USR=hudson
YUM_USR_KEY=~/.ssh/id_rsa
YUM_SRV=yum.cumulocity.com
YUM_DEST_DIR=/var/www/resources/cssdk/releases

for var in "$@"
for package in "$@"
do
echo "deploy $var to $YUM_SRV:${YUM_DEST_DIR}"
scp -Cr -i ${YUM_USR_KEY} $var ${YUM_USR}@${YUM_SRV}:${YUM_DEST_DIR}
echo "deploy $package to $YUM_SRV:${YUM_DEST_DIR}"
scp -o StrictHostKeyChecking=no -Cr $package ${YUM_USR}@${YUM_SRV}:${YUM_DEST_DIR}
# dotnet nuget push $package -k <token> v -s < source https://api.nuget.org/v3/index.json>
done

ssh -i ${YUM_USR_KEY} ${YUM_USR}@${YUM_SRV} '
win_scripts_latest="microservicesdk-win-dev-latest.zip"
lin_scripts_latest="microservicesdk-lin-dev-latest.zip"
cd /var/www/resources/cssdk/releases
if [ -f $win_scripts_latest ] ; then
echo remove_win_scripts
rm $win_scripts_latest
fi
win_scripts=$(ls -v | grep win-dev | tail -n 1)
if [ -z "$win_scripts" ]
then
echo "\$win_scripts is empty"
else
echo "\$win_scripts is NOT empty"
echo $win_scripts
cp $win_scripts microservicesdk-win-dev-latest.zip
fi
if [ -f $lin_scripts_latest ] ; then
echo remove_lin_scripts
rm $lin_scripts_latest
fi
lin_scripts=$(ls -v | grep lin-dev | tail -n 1)
if [ -z "$lin_scripts" ]
then
echo "\$lin_scripts is empty"
else
echo "\$lin_scripts is NOT empty"
echo $lin_scripts
cp $lin_scripts microservicesdk-lin-dev-latest.zip
fi
'

}
pwd
deploy publish/*.nupkg
Expand Down

0 comments on commit b4cad75

Please sign in to comment.