Jenkins Publish to Separate Repo than Source Managed - github

I'm trying to write a job in Jenkins that pulls my latest code from a Github repo, zips it all up, and then pushes it to another builds Github repo. The Publisher event in post-build seems to only push back to the repo you specify in source code management. Is there a way I can push to a different/separate repo?

You can create the zip and than use a bash command with git push ...
Another option is to keep the zip in artifacts repository - Nexus or artifactory ...

Related

Push large file to Azure repo but ignore in GitHub

I have a project linked to both a GitHub and Azure repo. This project has a saved tensorflow model on my workspace which my project manager is requesting I add to the Azure repo. I cannot add this to the GitHub repo as the file sizes are too large.
I have tried committing the files and then pushing to the Azure repo. Then uncommiting the file and pushing to the GitHub repo, but the next time I ran a push to the Azure repo, these files were lost as I had now uncommited them in the tree.
Is there a way to push these files to the Azure repo only, but ignore them for the GitHub repo?

how do i automatically pull code from master to fork in azure repos using azure devOps pipeline

I was trying to pull the code from master to fork repository automatically through the azure pipeline. If any one know about this?
If you fork azure repo and want to automatically sync the Fork repo using VSTS Git, please follow below steps.
Supposed the url of original repo is https://dev.azure.com/{organization}/{project}/_git/test, and the url of forked repo is https://dev.azure.com/{organization}/{project}/_git/test_fork.
If you click "Clone" button in test repository, you will see below panel.
Clicking "Generate Git Credentials" button will show the following panel.
So we can use command git remote add upstream https://username:password#dev.azure.com/{organization}/{project}/_git/test to specify it as the upstream of test_fork repo in script.
Now creating a build pipeline using Microsoft-hosted Windows agents, setting the test_fork as the source.
Adding the Command Line task with below script.
git remote add upstream https://username:password#dev.azure.com/{organization}/{project}/_git/test
git fetch upstream
git rebase upstream/master
git push -f origin HEAD:master
Queuing a new build and it will succeed to sync the test_fork repo using VSTS Git.
You can also configure schedules for this pipeline. Now everything is done.
If you use GitHub repo, please refer to this thread for guidance.

GitHub pipeline/CI to generate files and push them back to the repository

I maintain a public repository on GitHub where changes are only made to a single YAML file. I'm looking for a solution to process that file on every push and generate files based on it. Essentially, a pipeline or CI should parse the file and create many different markdown files. These files (or more specifically, the changes to these files) should then be pushed back to the repository.
Requirements:
Manual changes to the YAML file and automatic changes to the markdown files should both be pushed to the master branch.
The version history should be kept (e.g. forced push might not work).
There is an arbitrary number of files that are generated.
There are Travis providers for GitHub Pages and GitHub Releases. But both have limitations that make them unsuitable for my requirements.
Using what tool/CI/pipeline can I achieve that on GitHub? I would prefer a service over a self-hosted CI.
Assuming that you already have the program/script to parse the YAML file and to generate the Markdown files, I can give you some insights on how I would do this from Jenkins CI. While I draw my experience from running my own instance, there are also hosted options such as CloudBees that you can explore.
Create a new Jenkins Freestyle project.
Under the Source Code Management section, configure your GitHub project coordinates.
Under Build Triggers section, activate the 'Build when a change is pushed to GitHub' option. That would launch the CI job at the moment you push a new version of the YAML file into the repository.
Under the build section, add an Execute shell build step.
In the shell step, launch the program or script that processes the YAML file/generates the .md files. End the script by adding the git add ., git commit -m "message", git pull and git push commands (assumes git is in the path).
Enable the new job to make it active in Jenkins.
You can do this now with the free GitHub Actions option for the repositories.
You need to put this step into your YAML file.
- name: Commit back to GitHub
run: |
git config --global user.name "github-actiuons[bot]"
git config --global user.email "41898282+github-actions[bot]#users.noreply.github.com"
git add -A
git commit -m "Updating some file"
git push
There are some items in the marketplace, but they didn't work for me.
The email of the bot is based on this thread:
https://github.community/t/github-actions-bot-email-address/17204
Update the commit message.
Be careful with the folder paths if you decide to push a specific file in a folder.

On-premises GIT repository with Visual Studio Team Services Project

We have on-premises installed GIT. There we have our code repositories.
Is it possible to connect a repository from this on-premises instance to Visual studio team services project?
So they display under "Code" bar?
vsts
I need it hosted on premises, but see code changes/commits and other GIT stuff in VSTS project
No, it isn’t supported to display files or code of another repository under Code bar. You need to import that repository to the repository in VSTS. After that, you can push updates to VSTS repository if there are changes in your on-premises git repository.
You can't connect on premise GIT to VSTS. You may however use the VSTS rest APIs to push in code from your on premise GIT to VSTS.
Typically you will setup a hook/trigger on your on premise GIT repo in order to automate the replication process.
As others have said, you can have a "git hook", which is basically a git trigger to take action on some event. In this case, when code is pushed, to push it up to VSTS, but I assume you need to know the technical commands.
I had to do this the opposite way, and I did this quick and dirty. This pushes everything in one go, not each commit. This can also catch up a repo that is behind.
# Clone source repo (your local git repo)
git clone some_repo_path_goes_here
# I am skipping steps and assuming you are only syncing master branch.
# I have code to get all branches down before proceeding, but not posting it here.
# Assuming tags are on master branch..
# Get all tags
git fetch origin --tags
# Test to see if remote alias already exists
git ls-remote http://path_to_.visualstudio.com/org/project/_git/TargetRepoSameName
# Add a remote alias
git remote add any_name_123 http://path_to_.visualstudio.com/org/project/_git/TargetRepoSameName
# push local repo to 'any_name_123'
git push any_name_123 --all
# optional: delete all tags before attempting to push local tags
git push any_name_123 --delete `$(git tag -l)
# push local tags to remote repo
git push any_name_123 --tags
You can schedule this job if you would like. I have a PowerShell job to do this with a lot more functions to do pull down the branches.

Integrating Github code to TFS - auto check-in

We are using one of the project from Github. We need to check-in code of this project in our TFS.
We need to automate this process. Else everyday we need to download the code and then check-in.
Is there some plugin or some tool to automate this?
If you are using a TFVC repository in TFS then you'll probably want to build some scripts and a process around Git-TF to help automate some of this work.
If you are using a Git repository in TFS then you can create set up two remotes in a local Git repository, i.e
git remote add upstream https://github.com/foo/bar.git
git remote add origin https://tfsserver/DefaultCollection/_git/bar
And then simply do a git pull upstream master followed by a git push origin master assuming that master is the branch that you want to keep in sync.
With either version control system, you probably want to keep a branch in version control in your TFS repository to match what is in your upstream GitHub project so that you can easily see change coming in the one place and then handle your merges inside your local repository.