How to publish to another git after build using jenkins - node.js

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

Related

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.

Is there any way to send release pipeline data to GIT repo in devops?

Is there any task or something which will send the release pipeline data to git repo instead of sending it to any evironment?
You need to use the Invoke HTTP REST API task to call github api and create a file there.
No, there is not.
The only way you could do is running git commands in a release to git push files/data.
How to do this, you could refer below links:
Executing git commands inside a build job in Visual Studio Team Services (was VSO)
Run Git commands in a script

Execute a script after every git push

There is a server running and has a git instance on it. I want a script to run everytime a user does git push to the server. I want my script to be executed then git push to continue.
Any work arounds?
You've tagged this GitHub so I'm assuming that you are referring to public GitHub and not GitHub enterprise.
You cannot run a script "server-side" on GitHub's servers because that would obviously be a massive vulnerability but you can set up a web hook to trigger a script on another server.
Basically whenever someone does a push, a specific URL will be sent data about the push. You can then trigger a script from this. For more information on web hooks, see the GitHub API docs.
I am not sure If you want a scipt to run prior to push or after. So here is my answer for pre-push. But if you want post-push (i.e after push) you have to change the pre-push hooks accordingly to check if pushed successfully and then you can do post push thing.
As suggested by #Travis, git hooks is the one that you are looking for. So to execute a script pre-push, you have to do is to create a pre-push file in the .git/hooks. So in this case put your bunch of code in the pre-post script file .git/hooks/pre-push and save it. Then make it executable by chmod +x .git/hooks/pre-push. After you done with this successfully you will be able to see the script gets executed each time you do run push command.
PS: Please note that I haven't tested this whole but expected to work in this way.
In Short, assuming you(Linux user) are in the project directory
vim .git/hooks/pre-push # then add your code and save the file
# Also put the shebang on top to identify the interpreter
chmod +x .git/hooks/pre-push # make it executable
You should look into git hooks:
8.3 Customizing Git - Git Hooks
and, another site regarding this technology:
githooks.com

Jenkins to SCP a few folders and files from SVN to linux server?

I use jenkins to do auto deployment weekly to a tomcat server, and it is fairly simple to do using the "curl" with the tomcat manager. and since i am only uploading a .war file, so its very straight forward.
But when comes to a backend console application, Anyone has any idea how to use jenkins to upload an entire "set of folders with files" onto a linux box? The project that i have is built via ant and has all the folder inside the SVN.
A couple things come to mind.
Probably the most straightforward thing to do is use the ant scp task to push the directory / directories up to the server. You'll need the jsch jar on your Ant classpath to make it work, but that's not too bad to deal with. See the Ant docs for the scp task here. If you want to keep your main build script clean, just make another build script that Jenkins can run named 'deploy.xml' or similar. This has the added benefit that you can use it from places other than Jenkins.
Another idea is to check them out directly on the server from SVN. Again, ant can probably help you with this if you use the sshexec task, and run the subversion task inside of that. SSHexec docs here
Finally, Jenkins has a "Publish Over SSH" plugin you might try out. I've not used it personally, but it looks promising! Right over here!

Manipulating Jenkins build parameter with groovy script, used for sonar analysis

At the moment, i have Sourcetree making my branches, they will be called "feature/my-branch" and i can send that to my hg repo, and retrieve it from jenkins and build.
but, sonar does not accept "/" in the branch name, so i wanted to change "/" to "-" or something.. in a groovy script in the build phase.
Is something like that possible?
my solution so far:
parameter: BRANCH
default value: feature/my-branch
groovy scrips: def replaced = BRANCH.replaceAll(/\//, '-')
but it will not recognize my BRANCH, i've tried adding it in all sorts of ways..
any help to make my "feature/my-branch" be analyzed by sonar will be appreciated.
How are you invoking SonarQube on Jenkins? I assume it's via the SonarQube Jenkins Plugin. You could use the EnvInject Plugin to edit BRANCH. Here's an untested possibility for you to mull over:
SONAR_BRANCH=${BRANCH//\//-}
And in the SonarQube plugin's "Additional options":
sonar.branch=${env.SONAR_BRANCH}
If that won't work, or if you don't want EnvInject, you could do everything in one Execute Shell build step:
SONAR_BRANCH=${BRANCH//\//-}
mvn sonar:sonar -Dsonar.branch=${SONAR_BRANCH}

Resources