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



Friday, April 22, 2022

Update to Spring > 2.5

 I've recently updated one of our spring boot apps. We've used Spring Boot 2.4 and I update to the latest available 2.6. After restarting the tests and test application I noticed a problem with the initialization of the h2 db. 

We tend to use the former spring datasource properties 

spring.datasource.schema=classpath:dev/schema.sql

spring.datasource.data=classpath:dev/data.sql

which are renamed into spring.sql.init.*. So I also renamed them, but nothing happened so far. Neither schema nor data.sql gets called during startup. After reading the changes I noticed a hint in the Init Docu that you should not use the init scripts with higher level db migration tools like liquibase and flyway.

We are using flyway and that was causing the issue. Form Spring Boot 2.5.1 on the init script will be ignored if you are using flyway or liquibase (spring boot doc).

So I changed the way we init the dev and test h2 db. I set the 

spring.sql.init.mode=never

and removed the schema.sql and data.sql. To initially create and fill our db with flyway I added to flyway snippets using the flyway hook for beforeMigrate. As we have to script I used the standard flyway notation for the two scripts like the following

beforeMigrate__01_schema.sql

beforeMigrate__02_data.sql

After that change fly way runs the two scripts before starting the migration when using the h2 db. I only added the two script to our flyway h2 snippets.