Commit and Push in Job
A job can commit generated files and push them back to OneDev. The default checkout credential only has read permission for the current project, so configure a credential with code write permission first.
-
Create an access token with code write permission on the destination project. Branch protection rules still apply.
-
Open Settings → Build → Job Secrets, add a secret named
push-token, and store the token as its value. Authorize it for the branch whose jobs need it, for exampleon branch "main". -
In the job's Checkout Code step, select HTTP(S) for Clone Credential and
push-tokenfor Access Token Secret:- !CheckoutStepname: Checkout with write credentialcloneCredential: !HttpCredentialaccessTokenSecret: push-tokenwithLfs: falsewithSubmodules: falsecondition: SUCCESSFUL -
Add a Command step in an environment with Git installed. OneDev checks out the build commit, so fetch the destination branch and check it out before committing. This example writes the current build number:
set -eugit config user.name "Build Bot"git config user.email "build@@example.com"git fetch origin maingit checkout -B main FETCH_HEADprintf '%s\n' '@build_number@' > build_number.txtgit add build_number.txtif git diff --cached --quiet; thenexit 0figit commit -m "Update build number"git push origin HEAD:refs/heads/mainReplace
mainwith your destination branch. The doubled@@escapes a literal@in interpolated job commands. These Git identity settings apply only to the job's checkout.The remote URL must be reachable from the command environment. For local Docker Desktop testing, if
originuses host-locallocalhost, set a container-reachable URL before fetching, for example:git remote set-url origin http://host.docker.internal:6610/my-projectUse the appropriate URL for your installation. Concurrent branch updates can cause a non-fast-forward rejection; resolve that conflict instead of force-pushing.
-
If the job runs on branch updates, exclude generated files under Triggers → Branch update → Touched Files to prevent the pushed commit from triggering the same job again:
triggers:- !BranchUpdateTriggerbranches: mainpaths: '** -build_number.txt'userMatch: anyoneHere
**includes files and-build_number.txtexcludes the generated file. A commit changing another included file still triggers the job, even if it also changes the generated file.
Run the job and inspect both the build log and the destination branch. In this example, the HTTP checkout succeeded and the command pushed a new commit:

The generated-file-only commit should not start another build. Confirm the trigger still works by changing an included file; this distinguishes a working exclusion from a disabled or invalid trigger.