unable to execute Gitlab ci pipeline(.gitlab-ci.yml) file from separate gitlab repo - gitlab

I have two gitlab repos. Repo A (contains application source code), Repo B(contains gitlab-ci.yml file, a shell script and settings.xml file).
My idea is to separate the gitlab-ci.yml pipeline, shell script and settings.xml file from the application source code repos for security reasons.
For that, to call pipeline from repo B, config changes I did in repo A is as follows.
In Settings-->CI/CD-->General Pipelines->CI/CD config file
I have mentioned: .gitlab-ci.yml#gitlabgroup/subgroup/repoB
As I need shell script and settings file also. in the pipeline file(.gitlab-ci.yml) I and using curl command to download the shell script and settings.xml file.
When pipeline file is triggered(push event to repo A), I am getting below errors:
ERROR: Job Failed: command terminated with exit code 1
This error comes at the time of executing shell script and uses of settings.xml for mvn command in the pipeline are encountered.
. ./shell_script.sh cmd_arg1 and mvn help:evaluate -Dexpression="project.name -q -DforceSdtout -s settings.xml"
When I place .gitlab-ci.yml, shell script and settings.xml to repo A it executes without any error.
whenever I m trying to call the pipeline from another repo, I am getting the error.
I have checked, shell script and settings.xml files are downloaded properly.
unable to identify the actual cause of the error.
kindly help in resolving this error.
Thank You.

Related

Skipping file /opt/atlassian/pipelines/agent/build/. File does not exist

I have a file in my root directory catalog.json. I use a bitbucket pipeline to perform this step:
- aws s3 cp catalog.json s3://testunzipping/ --recursive
However, I get an error that:
Skipping file /opt/atlassian/pipelines/agent/build/catalog.json/. File does not exist.
Why is it checking for the catalog.json file in this path? Why is not extracting the file from the root? How can I modify the command accordingly?
The problem is that you are trying to use --recursive for a single file. The command is trying to evaluate it as a directory because of the --recursive parameter. And it's ending up giving File does not exist error. I reproduced it by trying to copy a single file with --recursive parameter, I got the same error, but after removing it, it worked.
You can use this ;
aws s3 cp catalog.json s3://testunzipping/
Also for the answer of your other question;
Bitbucket Pipelines runners are using /opt/atlassian/pipelines/agent/build directory. This is actually pipelines' root directory. Runners are pulling code from the repo there and processing it according to your pipeline structure. It's a built-in situation.

Maintain code on bash scripts or Jenkins?

I'm currently working with Linux VMs and I use Jenkins Pipelines to run various jobs written in bash. I have 2 options regarding where the code is wrote and maintained:
In pipelines with sh '#some code' (Git integrated)
In bash scripts placed in the VM with sh './bashscript'
Which one would you suggest?
Use GIT to store scripts or code related, as GIT is a version control system, and all users who have access can access the file for viewing or making changes.
When the Jenkins job runs, a workspace folder is created on the server in which the job is running on, and the script would be copied from GIT into the folder.

How does `autoreconf` create m4/ folder?

I hit a problem - and I detected the very strange situation:
I run Docker image locally and run there autoreconf -i and I get correct and robust ./configure script.
Then I run autoreconf -i in the same Docker image but under Gitlab CI. And I get broken ./configure script - some of M4 macro were not substituted to their shell code, so Bash cannot execute them and treats them as syntax errors.
The difference is in m4/ folder in the both runs: successful m4/ folder contains files like:
aria2_arg.m4
ax_check_compile_flag.m4
ax_cxx_compile_stdcxx_11.m4
codeset.m4
fallocate.m4
fcntl-o.m4
gettext.m4
... # and so on
but in the failed (Gitlab CI) m4/ folder there are:
gettext.m4
fcntl-o.m4
# ... and so on
and aria2_arg.m4, ax_check_compile_flag.m4, ax_cxx_compile_stdcxx_11.m4, fallocate.m4 and others are missing. I don't know how is it possible if the Docker image is the same in both cases, but... how does autoreconf create m4/ folder? If its content's source is the Docker image itself (I don't know is it true, it's my suggestion only), then why is the content different in both cases?
No any magic. The missing m4 files do exist in the original Aria2 Github repository (in m4/) folder. autoreconf -i adds another .m4 files to this folder. But it has .gitignore with .m4 rule. I added it to another git repo (to build it in Gitlab) but m4/ folder was ignored. So:
Aria2 -> local folder -> run docker -> OK
Github with m4/ locally m4/ exists
works fine, but:
Aria2 -> another git repo -> run Gitlab CI -> Failure
Github (now no m4/) (.m4 missing)
So, it seems the reason of the problem was - the miss of m4/ in the second git repo (at least I have got the first successful build)

How to publish to another git after build using jenkins

I have a private repo and want to publish the build artifacts to another public repo (it's the packaged application)
How can I do that in jenkins? I could only find publish on the git I've used to build.
Thanks
There are multiple ways to do this:
- Using a shell script that calls the GIT command line tool. This can be a post-build script, the same script compiling the code, etc.
- Same thing in groovy
- Call a downstream job to do that for you (probably the best solution IMHO)
The main problem would be the GIT credentials, but that is not an big issue...

Custom git command autocompletion

I have implemented a custom git command by writing a shell script located in /usr/local/bin. It works fine, but I would like the script to autocomplete branches in the command line, just like git checkout [TAB][TAB]. How could this be done?
EDIT:
Just adding some context: git allows you to very easily add your own commands by creating a script git-$subcommandName. In my case here git-install, the script facilitates checking out a branch, building, packaging, and installing the source code.
Figured it out. I needed to download git bash completion (here), create a new file in /etc/bash_completion.d with the following contents:
source ~/.git-completion.bash
_git_install ()
{
__gitcomp_nl "$(__git_refs)"
}
and then exec bash to reload completion scripts.

Resources