Skip to content

Commit

Permalink
Merged in feature/MTM-35567/migrate_jenkinsfile (pull request #16)
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
piotr.szczepaniak committed Feb 12, 2021
2 parents 0da7e87 + fda8999 commit 637387c
Show file tree
Hide file tree
Showing 6 changed files with 216 additions and 19 deletions.
137 changes: 137 additions & 0 deletions .jenkins/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
pipeline {
agent {
kubernetes {
label 'mono3'
inheritFrom 'mono3'
defaultContainer 'default'
}
}
triggers{
bitbucketPush()
}
options{
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 1, unit: 'HOURS')
disableConcurrentBuilds()
}
parameters {
booleanParam(defaultValue: true, description: '', name: 'DIAGNOSTIC_FLAG')
booleanParam(defaultValue: false, description: '', name: 'CAN_RELEASE')
}
environment {
CI = 'true'
}
stages {
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'
}
}
}
}
}
stage('Deliver for development') {
when {
branch 'development'
}
steps {
sh 'echo DevelopmentBranch'
}
}
stage('Release') {
when {
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}"
}
}
}
}
}

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'
}
}

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: 29 additions & 0 deletions .jenkins/build_only.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
pipeline {
agent{
label 'mono3'
}
options {
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '5'))
disableConcurrentBuilds()
}
stages {
stage('Checkout') {
steps {
container('default') {
checkout([
$class: 'GitSCM', branches: [[name: 'feature/MTM-35567/migrate_jenkinsfile']],
extensions: [[$class: 'CleanCheckout']],
userRemoteConfigs: [[url: 'git@bitbucket.org:m2m/cumulocity-clients-cs.git',credentialsId:'jenkins-master']] ])
}
}
stage('Build') {
steps {
container('dotnet-sdk-3-1') {
sshagent(['jenkins-master']){
sh 'cd DeviceSDK/MQTT/ && chmod +x ./build.sh && pwd && ./build.sh -target=Test'
}
}
}
}
}

6 changes: 6 additions & 0 deletions .jenkins/scripts/kill.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh

echo 'The following command terminates the "npm start" process using its PID'
echo '(written to ".pidfile"), all of which were conducted when either'
set -x
kill $(cat .pidfile)
13 changes: 13 additions & 0 deletions .jenkins/scripts/status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash


function update-status {
commitId=${GIT_REVISION}
status=${1}
name=${2}
key=$( echo $3 | rev | cut -c -40 | rev )
echo "Sending build status update for commitId: ${commitId}, status: ${status}, name: ${name} , key: ${key}"
echo $(curl -s --user ${BITBUCKET_USER}:${BITBUCKET_PASSWORD} -H "Content-Type: application/json" -X POST https://api.bitbucket.org/2.0/repositories/m2m/cumulocity-clients-cs/commit/${commitId}/statuses/build --data "{\"state\":\"${status}\", \"name\": \"${name}\", \"key\": \"${key}\", \"url\": \"http://localhost:8081/job/Cumulocity-CsSDK/job/${BRANCH_NAME}/${BUILD_ID}/\", \"description\": \"\" }")
}

update-status $1 $2 $3
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,25 @@ public void ClientTest_WsConnection_CheckTemplateCollectionExists_NotExist_IoTHu
}

[Test]
public void ClientTest_WsConnection_CheckTemplateCollectionExists_CreateGetInventoryDataAsync()
{
var res2 = Task.Run(() => cl.MqttCustomSmartRest.CreateTemplateDataAsync("GetTemplate4",
new List<Request> {
new InventoryGetRequest("9999",null, String.Empty, true),
new InventoryGetRequest("9998",null, "c8y_Serial", false)
},
new List<Response> {
new Response("8889",
String.Empty,
"c8y_IsDevice",
new List<string> { "type", "c8y_MQTTDevice", "c8y_Mobile.cellId" }),
new Response("8888",
String.Empty,
"c8y_IsDevice",
new List<string> { "type", "c8y_MQTTDevice", "c8y_Mobile.cellId" })
})).Result;
Assert.IsTrue(res2);
}
// public void ClientTest_WsConnection_CheckTemplateCollectionExists_CreateGetInventoryDataAsync()
// {
// var res2 = Task.Run(() => cl.MqttCustomSmartRest.CreateTemplateDataAsync("GetTemplate4",
// new List<Request> {
// new InventoryGetRequest("9999",null, String.Empty, true),
// new InventoryGetRequest("9998",null, "c8y_Serial", false)
// },
// new List<Response> {
// new Response("8889",
// String.Empty,
// "c8y_IsDevice",
// new List<string> { "type", "c8y_MQTTDevice", "c8y_Mobile.cellId" }),
// new Response("8888",
// String.Empty,
// "c8y_IsDevice",
// new List<string> { "type", "c8y_MQTTDevice", "c8y_Mobile.cellId" })
// })).Result;
// Assert.IsTrue(res2);
// }

[Test]
[Ignore("Firewall")]
Expand Down
12 changes: 12 additions & 0 deletions jenkins/scripts/scan_dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
if [ -z "$TPP_FETCHER_URL" ]; then TPP_FETCHER_URL="http://172.30.0.129:8083"; fi


if [[ -e Tpp.toml ]] ; then
curl -sS -o tpp-scanner ${TPP_FETCHER_URL}/tpp-scanner \
&& chmod +x tpp-scanner \
&& ./tpp-scanner -tpp-fetcher-url ${TPP_FETCHER_URL} \
&& rm tpp-scanner
exit 0
fi

0 comments on commit 637387c

Please sign in to comment.