docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk11
Jenkins Docker Image Run
pipeline {
agent any
parameters {
string defaultValue: 'internalEventListener', description: 'Iflow Name', name: 'Name', trim: true
}
//Configure the following environment variables before executing the Jenkins Job
environment {
IntegrationFlowID = "${Name}"
CPIHost = "${env.CPI_HOST}"
CPIOAuthHost = "${env.CPI_OAUTH_HOST}"
CPIOAuthCredentials = "${env.CPI_OAUTH_CRED}"
GITRepositoryURL = "${env.GIT_REPOSITORY_URL}"
GITCredentials = "${env.GIT_CRED}"
GITBranch = "${env.GIT_BRANCH_NAME}"
GITFolder = "IntegrationContent/IntegrationArtefacts"
GITComment = "Integration Artefacts update from CICD pipeline"
}
stages {
stage('download integration artefact and store it in GitHub') {
steps {
deleteDir()
script {
//clone repo
checkout([
$class: 'GitSCM',
branches: [[name: env.GITBranch]],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'RelativeTargetDirectory',relativeTargetDir: "."],
//[$class: 'SparseCheckoutPaths', sparseCheckoutPaths:[[$class:'SparseCheckoutPath', path: env.GITFolder]]]
],
submoduleCfg: [],
userRemoteConfigs: [[
credentialsId: env.GITCredentials,
url: 'https://' + env.GITRepositoryURL
]]
])
//get token
println("Request token");
def token;
try{
def getTokenResp = httpRequest acceptType: 'APPLICATION_JSON',
authentication: env.CPIOAuthCredentials,
contentType: 'APPLICATION_JSON',
httpMode: 'POST',
responseHandle: 'LEAVE_OPEN',
timeout: 30,
url: 'https://' + env.CPIOAuthHost + '/oauth/token?grant_type=client_credentials';
def jsonObjToken = readJSON text: getTokenResp.content
token = "Bearer " + jsonObjToken.access_token
} catch (Exception e) {
error("Requesting the oauth token for Cloud Integration failed:\n${e}")
}
//delete the old flow content so that only the latest content gets stored
dir(env.GITFolder + '/' + env.IntegrationFlowID){
deleteDir();
}
//download and extract artefact from tenant
println("Downloading artefact");
def tempfile = UUID.randomUUID().toString() + ".zip";
def cpiDownloadResponse = httpRequest acceptType: 'APPLICATION_ZIP',
customHeaders: [[maskValue: false, name: 'Authorization', value: token]],
ignoreSslErrors: false,
responseHandle: 'LEAVE_OPEN',
validResponseCodes: '100:399, 404',
timeout: 30,
outputFile: tempfile,
url: 'https://' + env.CPIHost + '/api/v1/IntegrationDesigntimeArtifacts(Id=\''+ env.IntegrationFlowID + '\',Version=\'active\')/$value';
if (cpiDownloadResponse.status == 404){
//invalid Flow ID
error("Received http status code 404. Please check if the Artefact ID that you have provided exists on the tenant.");
}
def disposition = cpiDownloadResponse.headers.toString();
def index=disposition.indexOf('filename')+9;
def lastindex=disposition.indexOf('.zip', index);
def filename=disposition.substring(index + 1, lastindex + 4);
def folder=env.GITFolder + '/' + filename.substring(0, filename.indexOf('.zip'));
def zipfolder=env.GITFolder + '/ZipFiles';
fileOperations([fileUnZipOperation(filePath: tempfile, targetLocation: folder)])
fileOperations([fileRenameOperation(source: tempfile, destination: filename)])
fileOperations([fileCopyOperation(includes: filename, targetLocation: zipfolder)])
env.Filename = filename;
cpiDownloadResponse.close();
//remove the zip
fileOperations([fileDeleteOperation(excludes: '', includes: filename)])
dir(env.GITFolder){
sh 'git add .'
}
println("Store integration artefact in Git")
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: env.GITCredentials ,usernameVariable: 'GIT_AUTHOR_NAME', passwordVariable: 'GIT_PASSWORD']]) {
sh 'git diff-index --quiet HEAD || git commit -am ' + '\'' + env.GitComment + '\''
sh('git push https://${GIT_PASSWORD}@' + env.GITRepositoryURL + ' HEAD:' + env.GITBranch)
}
}
}
}
stage('Code Analysis') {
steps {
script{
def zipcpilintfile = "cpilint-1.0.4.zip";
def unzipcpilintfile = "cpilint";
fileOperations([fileUnZipOperation(filePath: zipcpilintfile, targetLocation: unzipcpilintfile)])
fileOperations([fileDeleteOperation(excludes: '', includes: zipcpilintfile)])
sh "chmod a+rwx -R $WORKSPACE/cpilint"
sh "$WORKSPACE/cpilint/cpilint-1.0.4/bin/cpilint -rules $WORKSPACE/rules.xml -files $WORKSPACE/IntegrationContent/IntegrationArtefacts/ZipFiles/${env.Filename}"
}
}
}
}
}
Jenkinsfile
<?xml version="1.0" encoding="UTF-8"?>
<cpilint>
<rules>
<!-- Require that all iflows have a description. -->
<iflow-description-required/>
<!-- Don't allow the social media receiver adapters. -->
<disallowed-receiver-adapters>
<disallow>facebook</disallow>
<disallow>twitter</disallow>
</disallowed-receiver-adapters>
<!-- Don't allow Router steps configured with both XML and non-XML conditions. -->
<multi-condition-type-routers-not-allowed/>
<!-- Message Mapping and XSLT are the two allowed mapping types. -->
<allowed-mapping-types>
<allow>message-mapping</allow>
<allow>xslt-mapping</allow>
</allowed-mapping-types>
<!-- Make sure that all data store writes are encrypted. -->
<unencrypted-data-store-write-not-allowed/>
</rules>
</cpilint>
GitHub Repository Files
HTTP URL
Service Key
CPI Cred
GitHub Cred
Name | Value |
CPI_HOST | {{url value from Service Key without https://}} e.g. xxxxxxxxxxx.it-cpi002.cfapps.ap10.hana.ondemand.com |
CPI_OAUTH_CRED | CPIOAuthCredentials |
CPI_OAUTH_HOST | {{tokenurl value from Service Key without https://}} e.g. xxxxxxxxxxx.authentication.ap10.hana.ondemand.com |
GIT_BRANCH_NAME | Main |
GIT_CRED | GIT_Credentials |
GIT_REPOSITORY_URL | github.com/Asutosh-Integration/IFlowRepo.git |
Environment Variable
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com"
Multibranch Pipeline Configuration
Branch Source
Build with Parameter
Build status
Change in Iflow and Save as a version
Diff
cpilint logs
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Subject | Kudos |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
User | Count |
---|---|
10 | |
7 | |
7 | |
7 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 |