gitlab

Read and write file in gitlab CI


I want to have a gitlab CI in which a file named "version" will be read out (content will be like 1.1.0) and release my nuget with this version and then increase the minor number for the next time (e.g. 1.2.0 then).

this is my file now:

nuget_prod:    
  stage: nuget_prod    
  script:     
    - 'export VERSION=1.1.0' #READ FROM VERSION FILE
    - 'TODO' # ADD VERSION NUMBER AND SAVE BACK TO VERSION FILE
    - 'dotnet pack .\\myproj.csproj -p:PackageVersion=$VERSION'
    - 'dotnet nuget push **/*.nupkg --api-key xxxx--source xxxx'
  when: manual
  only:
    - master

Solution

  • You have some approaches here

    1. Save the value in a external service, like a database or file (through scp)
    2. Configuring the cache https://docs.gitlab.com/ee/ci/yaml/#cache it is not the best practice but it will work in this case
    3. Saving the file with the version as a artifact https://docs.gitlab.com/ee/ci/jobs/job_artifacts.html and fetch this file from api https://docs.gitlab.com/ee/api/jobs.html in the next pipeline
    4. Configure your pipeline to commit a new version of this file (with CI SKIP) at the end of the pipeline

    It is not a hard task, there is a lot of ways to do it....just test which fits better in your environment