You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Alright so I created a pipeline that calls a bash script whenever a commit is made to the master branch. In that bash script, I would like to open up a file in the branch that the commit was made to, update a number in it, then commit that new change. How can I go about doing that in a pipeline bash script? I'm not sure if I can have the bash script do a checkout or not.
Thank you for reaching out to the community.
You can definitely run Git commands in your bash script.
When it comes to changing your file on Pipelines, there's no option for you to open a file and edit it while the build is running.
You can, however, automate this process and we usually recommend using the "sed" command.
Sed Linux command will allow you to change a value in a file and save the final output using Git commands.
Here's an example of how to use the Sed command:
- apt-get install -y sed - sed 's/dev/prod/g' production.env - your_script_here.bash
(1) You'll need to install it on Pipelines first
(2) Here, I want to change the value "dev" to "prod" in the file production.env
(3) Do save the file changes using Git commands inside the bash script (e.g. Git add, commit, and push). Please also refer to this link for an example of how to push back to your repository.
Here are some relevant resources about Sed command as well:
Hope it helps and let me know how you go with the Sed command.