Git Repository Push Pull via Jenkins Pipeline

This documentation references one possible pipeline where repository items from the DEV environment will be pushed to the Git Repository and afterwards will be pulled into the UAT environment from the same Git Repository.

Part 1: ETL Chainset

image

image

Key Description
repo-url The git repository URL (usually in the format git@git.example.com:somegroup/somerepo.git) You may also use an {enc} encoded string, or a {secret} reference as shown in the above example. Do refer to part 1B for more details on how to use encoded string/secret reference.
repo-path The folder to be pushed to git
repo-branch The field holding the branch name to push to

Part 1B: Using Encoded String or Secret Reference

Using Encoded String

  1. Do refer to the following support entry for the steps on how to encrypt plain text strings: Encrypting using Ambience/Repertoire 202x

  2. Once done, the “repo-path” parameter would be defined similar to the following:

    “repo-path”:” {enc:elx-2.0}fxxfGHDkxxxOGdxxxwVWRo=”

Using Secret Reference

  1. Navigate to the Secrets module and click on the “Add” button to add a new secret.

  2. Input in the values. The “Secret Text” field would be the value of your GitLab Repository URL path.

    image

  3. Once done, click “OK”.

  4. After doing so, the “repo-path” parameter would be defined similar to the following:

    “repo-path”:”{secret}git-repo”.

Part 2: Create API Endpoint

  1. Navigate to the “API Token” module and create a token.

  2. Edit step “HTTP Endpoint” and copy the JSON Endpoint value.

  3. Copy value derived in step 1 to “api-token” and value derived in step 2 to “byte-endpoint-value”.

    curl -v <byte-endpoint-value> ?elx.token=<api-token> -H "Content-Type: application/json"

  4. To define parameters directly from the API call:

    To do this, please ensure that parameters defined in the ETL chainset are disabled or removed. (i.e. the ETL steps JSON Record/JSON Token Record)

    curl -v <byte-endpoint-value> ?elx.token=<api-token> -H "Content-Type: application/json" -d '{"repo-url ":"{secret}git-repo","repo-branch ":"test", "repo-path ":"/ElixirSamples"}'

Additionally, remember to revise any characters that need to be encoded as their respective representations in URLs.

For example, whitespaces becomes %20

Before:

http://localhost:1750/etl/endpoint/GitRepository/70 - Remote-GitPullToAmbienceRepo

After:

http://localhost:1750/etl/endpoint/GitRepository/70%20-%20Remote-GitPullToAmbienceRepo

Part 2B: CURL call Examples

Git Push

curl -v \http://localhost:1750/etl/endpoint/repo-git/Remote-GitPushtoRemoteGit?\elx.token=a75b144d-5cc2-4c68-8624-04b4a21e6ba9 -H "Content-Type: application/json" \-d '{"repo-url":"{secret}git-repo","repo-branch":"test", \"repo-path":"/ElixirSamples"}'
* Trying 127.0.0.1:1750...

* Connected to localhost (127.0.0.1) port 1750 (#0)

> POST /etl/endpoint/repo-git/Remote-GitPushtoRemoteGit?elx.token=a75b144d-5cc2-4c68-8624-04b4a21e6ba9 HTTP/1.1

> Host: localhost:1750

> User-Agent: curl/8.1.2

> Accept: */*

> Content-Type: application/json

> Content-Length: 93

>

< HTTP/1.1 200 OK

< Cache-Control: max-age=0, must-revalidate

< X-Content-Type-Options: nosniff

< X-Frame-Options: SAMEORIGIN

< X-XSS-Protection: 1; mode=block

< Content-Type: application/json; charset=utf-8

< content-length: 178

< connection: keep-alive

<

[{

"_id": {

"$oid": "677f493dec7cd15b27eb657b"

},

"repo-url": "{secret}git-repo",

"repo-branch": "test",

"repo-path": "/ElixirSamples",

"_elxIdx": 1

* Connection #0 to host localhost left intact

}]

Git Pull

curl -v \http://localhost:1745/etl/endpoint/repo-git/Remote-GitPullToAmbienceRepo? \ elx.token=f2ff0b9a-5ec7-4ed0-9bc1-f54d1294d146 -H "Content-Type: application/json" \-d '{"repo-url":"{secret}git-repo","repo-branch":"test"}'
* Trying 127.0.0.1:1745...

* Connected to localhost (127.0.0.1) port 1745 (#0)

> POST /etl/endpoint/repo-git/Remote-GitPullToAmbienceRepo?elx.token=f2ff0b9a-5ec7-4ed0-9bc1-f54d1294d146 HTTP/1.1

> Host: localhost:1745

> User-Agent: curl/8.1.2

> Accept: */*

> Content-Type: application/json

> Content-Length: 62

>

< HTTP/1.1 200 OK

< Cache-Control: max-age=0, must-revalidate

< X-Content-Type-Options: nosniff

< X-Frame-Options: SAMEORIGIN

< X-XSS-Protection: 1; mode=block

< Content-Type: application/json; charset=utf-8

< content-length: 144

< connection: keep-alive

<

[{

"_id": {

"$oid": "677f4a11214dda23dbb1aa5b"

},

"repo-url": "{secret}git-repo",

"repo-branch": "test",

"_elxIdx": 1

* Connection #0 to host localhost left intact

}]

Part 3: Create Jenkins Pipeline

Sample Pipeline Script

pipeline {
    agent any
    stages {
        stage('Dev Repo Push to RemoteGit') {
            steps {
                script {
                    sh '''
                    curl -v http://localhost:1740/etl/endpoint/repo-git/Remote-GitPushtoRemoteGit?elx.token=xxx" -H "Content-Type: application/json"
                    '''
                }
            }
        }
        stage('UAT Repo Pull from RemoteGit') {
            steps {
                script {
                    sh '''
                    curl -v "http://localhost:1745/etl/endpoint/repo-git/Remote-GitPullToAmbienceRepo?elx.token=xxx" -H "Content-Type: application/json"
                    '''
                }
            }
        }
    }
}

Steps to Create

  1. From Jenkins dashboard, click on “New item”.

  2. Give the item a name, select “Pipeline” and click “Ok”.
    image

  3. Scroll all the way down to the Pipeline section.

  4. Paste in the pipeline script as shown in the screenshot below.

image

  1. Once done, click “Apply” and “Save”.

  2. The pipeline should start building and if successful, report templates from the Dev environment should successfully be pushed to the Git Repository and pulled into the UAT environment.