Search This Blog

Wednesday, September 28, 2022

Sample Jenkinsfile

This is a sample for a Jenkinsfile with following features in use:


pipeline {
  agent any
  parameters {
string(name: 'app', defaultValue: 'sample', description: 'Name of the app')

RESTList(
      name: 'MILESTONE',
      description: '',
      restEndpoint: 'https://git.gitlab.com/api/v4/projects/234/milestones',
      credentialId: 'CREDENTIAL_ID_IN_JENKINS',
      mimeType: 'APPLICATION_JSON',
      valueExpression: '$[*]',
      displayExpression: '$.name',
      cacheTime: 10,    // optional
      defaultValue: '', // optional
      filter: '.*',     // optional
      valueOrder: 'ASC' // optional
    )

    choice(name: 'sampleChoice', choices: 'True\nFalse', description: 'Well just a sample choice. First entry is defaultValue.')
    
  }
  stages {
stage('Prepare landing zone') {
steps{
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[credentialsId: 'CREDENTIAL_ID_IN_JENKINS', url: 'git@git.gitlab.com:sample/repository.git']]])
}  
}
    stage('Excute whatever you like') {
        
      steps {
script {
// parse the milestones retreived from gitlab
ms = readJSON returnPojo: true, text: env.MILESTONE
// save the milestone iid within the env
env.milestoneId =  ms.iid
}
withCredentials([string(credentialsId: 'CREDENTIAL_ID_IN_JENKINS', variable: 'accesToken')]) {
println accesToken: accesToken
println app: app
println sampleChoice: sampleChoice
println milestoneId: milestoneId
sh ('printenv')
dir('out') {
    sh ('pwd -P')
}
    sh ('echo $accesToken $gitLabProjectMode $app $sampleChoice $milestoneId')
}
      }
    }
  }