Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,463,603
Community Members
 
Community Events
176
Community Groups

How to have pipeline bash script edit a file?

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. 

1 answer

0 votes
Mark C Atlassian Team Feb 13, 2022

Hi @Michael Pietrefesa,

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.

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events