Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Before we do automated migrations via the API, you need to prepare your AAGM and set git as the single point of truth for your API.

Working with git

Jenkins

Set up Jenkins

Copy this docker-compose.yml, adjust the ports and boot up your Jenkins!

...

The initial password of the admin can be found either in the logs of the container or in the mounted folder secrets.

Needed Plugins

For our project we still need a few plugins.

...

https://plugins.jenkins.io/http_request/

Connect to GitLab

http://localhost:8033/credentials/

Add your GitLab credentials as global Credentials

...

Setup Pipeline

Create a Multibranch Pipeline

...

In "Scan Multibranch Pipeline Triggers", set the intervals at which Jenkins should check for updates in your repository.

Jenkinsfile

Code Block
breakoutModefull-width
pipeline {

    agent any
    
    stages {
    
        stage("is AAGM alive?") {
        
            steps {
				script {
				    echo '------------------------------------------------'
					echo '---------------  is AAGM alive?  ---------------'
					echo '------------------------------------------------'
				
					def response = httpRequest "http://host.docker.internal:8090/api/v1/alive"
					println('Response: '+response.content)
				}
            }
        }
    
        stage("is AAGM ready?") {
        
            steps {
				script {
				    echo '------------------------------------------------'
				    echo '---------------  is AAGM ready?  ---------------'
				    echo '------------------------------------------------'
				
					def response = httpRequest "http://host.docker.internal:8090/api/v1/ready"
					println('Response: '+response.content)
				}
            }
        }
    
        stage("Login and Deploy") {
        
            steps {
				script {
				    echo '------------------------------------------'
				    echo '---------------  Login...  ---------------'
				    echo '------------------------------------------'
				    
				    def bodyLogin = '{"user": "mirco.hoffmann@apiida.com","pass": "myPassword"}'
				    def response = httpRequest contentType: 'APPLICATION_JSON', httpMode: 'POST', requestBody: "${bodyLogin}" , url: "http://host.docker.internal:8090/api/v1/login"
					println('Response Content: '+response.content)

                    echo '-------------------------------------------'
                    echo '---------------  Deploy...  ---------------'
                    echo '-------------------------------------------'

                    def jsonObj = readJSON text: response.content
                    echo 'Token: '+jsonObj.token 
				
				    def body = '{"source": {"type": "git"},"targets": ["myTargetNode"],"comment": "Test Migration over API"}'
					
					def migResponse = httpRequest customHeaders:[[name:'X-Token', value:"${jsonObj.token}"]] ,contentType: 'APPLICATION_JSON', httpMode: 'GET', requestBody: "${body}" , url: "http://host.docker.internal:8090/api/v1/apis/myApiId/migrate"
					println('Response: '+migResponse.content)
				}
            }
        }
    }
    
}

...