I'm trying to create a file into my repository with the version of the current build, that gets updated automatically whenever there's a push to the main. I've tried using
- task: Bash@3
inputs:
targetType: 'inline'
script: |
sudo echo "$(major).$(minor).$(patch)" > version.txt
cat version.txt
But, even if the cat command shows the correct content, the file is not getting created on the repo.
One colleage of mine suggested me using an artifact, and I've developed the following code:
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
sudo echo "$(major).$(minor).$(patch)" > version.txt
cat version.txt
- task: PublishPipelineArtifact@1
inputs:
publishLocation: filepath
targetPath: version.txt # path to the folder or file to publish
artifactName: version # name of the artifact to create
The artifact is correctly made and I can download it and see the correct version number. Is there a way to push this artifact directly into the root of the main branch of my Azure repo? Thanks in advance.
CodePudding user response:
Is there a way to push this artifact directly into the root of the main branch of my Azure repo?
Jukkak is right. To push the artifact (version.txt
in your scenario) directly into the root of the main branch of Azure repo, you need to run git commands to add the version.txt
file and then commit it to push into the repo. See
CodePudding user response:
You would need to do git add and commit after creating the file (I presume you are using Git since you are talking about repository):
The artifact you are talking about is really just a concept, and not a tangible thing you can or should be committing anywhere. In reality when you are publishing a pipeline artifact you are really just storing a file, folder structure or a compressed package somewhere where it can be downloaded by another stage or pipeline. In your example, it's just a file, so you'll commit that file. You would, of course, need to checkout the main-branch if the pipeline checks out some other branch at the start of the run.