Hello Miguel,
If you wish to automate the 'push' from the local GIT repository to the hosted GitHub or Bitbucket repository, you can do the following;
1. Navigate to your local GIT repository in the IFS.
2. Link your local GIT repository to your hosted GitHub or Bitbucket account using the standard GIT commands.
3. Create and save a 'filename.sh' script, and insert the following code (changing the highlighted text with the appropriate values);
************Beginning of data**************
#!/bin/sh
LOG="
/tmp/filename.txt"
REPO_DIR="
/path/to/your/local/GIT Repository"
cd $REPO_DIR > $LOG 2>&1
if ^^ -n $(git status -s) ]]; then
git add --all . >> $LOG 2>&1
git commit -m "
Commit from IFS_systemname" >> $LOG 2>&1
git push -u origin master >> $LOG 2>&1
fi
************End of Data********************
4. To automate the execution of the above script upon an LMi promotion, you could choose to update the EXIT program to include the following code;
QSH CMD('/QOpenSys/usr/bin/sh -c "/path/to/your .sh script.sh"') /* command to push local Git in IFS into GitHub or Bitbucket Server */
/**/
OR
Have a batch job running that loops around and executes the above command periodically, by creating a CL program as shown below;
PGM
DCL VAR(&COUNT) TYPE(*DEC) LEN(3 0) VALUE(1)
/* */
/* SUBMIT A JOB TO RUN EVERY 30 SECS FOR ONE HOUR */
/* 30SECS X 240 = 7200 SECS / 60 = 120 MINS */
DOUNTIL COND(&COUNT = 240) /* TOTAL OF 1 HOUR RUNNING JOB
QSH CMD('/QOpenSys/usr/bin/sh -c +
"/path/to/your .sh script.sh"') /* command to push local +
Git in IFS into Github or Bitbucket Server */
/**/
CHGVAR VAR(&COUNT) VALUE(&COUNT + 1)
DLYJOB DLY(30)
ENDDO
ENDPGM
*Please note that you may be required to use SSH keys to authenticate from the local GIT repository to the online GitHub or Bitbucket repository.
A key can be generated on the IBMi by accessing QSH, and using the 'ssh-keygen' command. Once the key is generated, open the file using the 'cat' command, and copy the full key, which will start with 'ssh-rsa' followed by the unique key, and add this to the online GitHub or Bitbucket repository for this user.
I hope this helps,
Many thanks, Andy.
------------------------------
Andy Finley
Rocket Software
------------------------------
Original Message:
Sent: 05-07-2021 10:19
From: Miguel Garcia
Subject: How do I get Source Code from LMi into Github or BitBucket?
Hello Andy,
This post is really fantastic, I have adjusted these instructions too many customers with success.
Do you have an example about "Writing a CL program that navigates to the appropriate path and executes the above Git commands"
I would like to run the git push command automatically from IBMi
Best regards and congratulations for your great post !
Miguel
------------------------------
Miguel Garcia - Partner
IT Specialist
CDS Americas
Quito - Pichincha - Ecuador
Original Message:
Sent: 03-17-2021 07:32
From: Andy Finley
Subject: How do I get Source Code from LMi into Github or BitBucket?
Many of our customers are choosing to store a copy of their IBMi source code from LMi, within a centrally accessible online repository such as Github or BitBucket, for code analysis purposes, or centralisation with distributed systems.
If you wish to do this, here is what you need to do…..
1. Start by checking your product compatibility. The LMi Git integration commands were introduced in Rocket Lifecycle Manager for IBMi Edition (LMi) Version 8.3. If you are on a version prior to this, contact us to discuss upgrading options.
2. Go to https://docs.rocketsoftware.com and download the Rocket Lifecycle Manager for IBMi Edition Daily Operations Reference Version 8.x (where x is the version of LMi). Navigate to the Appendix section within the document and open the 'Configuring the LMi Git Integration' topic. Check the Prerequisites section to ensure you have the correct licensed programs and credentials required. The GIT licensed program must be installed on the IBMi server.
3. Follow the instructions in the guide to complete the tasks listed below.
- Use the LMIGITBASE command to define the local Git working directory.
- Use the LMIGITSYNC command to populate the local git repository with LMi source files from within a single Group/Application/Release or choose to add ALL source files within LMi to the Git repository in a single operation.
- Use the LMIGITEXIT program to configure the LMi exit programs, so that the local Git repository is updated automatically during an LMi Promotion action.
- Configure the LMIGITNEP monitor job.
Once the configuration is complete, test that your local Git repository is updated by checking out an object and perform a promotion action as normal. Navigate to the path where the Git working directory was created using the WRKLNK command and locate the source file that was changed.
4. This next section references how to push the changes from the local Git working directory upto Github or BitBucket. This is not described within the Rocket documentation guide, as it uses standard Git commands. The configuration actions that should be considered are;
- Link the local Git working directory to your GitHub or BitBucket repository using the 'git remote add origin URL' command (where URL is the address of the GitHub or BitBucket repository).
- Create SSH keys if this is required by your organisation. The SSH keys can be generated on the IBMi server using the ssh-keygen command, and then added to the GitHub or BitBucket repository list of keys for authorised users. We would recommend searching the ibm.com website for further information on this command if you are not already familiar with it.
Once the configuration is complete, to send the changes to the attached GitHub or BitBucket repository, the push is performed using the standard Git commands 'git add, git commit, git push', which can be done in several ways;
- Using an SSH terminal session such as PuTTY and navigating to the Git working directory using the 'cd' command.
- Using STRQSH on the IBMi server and navigating to the Git working directory.
- Writing a CL program that navigates to the appropriate path and executes the above Git commands.
So, as you can see, it is a simple job to get all source files within LMi into a centralised repository such as GitHub or BitBucket and have them updated when future changes occur. If you have any other questions on the LMi Git Integration, just ask!
------------------------------
Andy Finley
Rocket Software
------------------------------