Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Html macro
<iframe width="744" height="418" src="https://www.youtube-nocookie.com/embed/S448Mr6X9Qc?si=RasttqZOP87rUIdh" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>

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 Work 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

...

Insert the Repository URL of ur API at “Branch Sources” and select your credentials.

...

If you want to have your Jenkinsfile in another repository, select "by Remote Jenkinsfile Provider Plugin" in "Build Configuration" instead of "by Jenkinsfile", then git in "Jenkinsfile SCM" and enter the repository URL of your Jenkinsfile there.

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?user=mirco.hoffmann@apiida.com&pass=masterkeymasterke"
					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": [{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/{id}myApiId/migrate"
					println('Response: '+migResponse.content)
				}
            }
        }
    }
    
}

In line 53 54 you have to define the targets of the migration.

In line 55 56 you have to insert the id of the API you want to migrate.

...