Search code examples
jenkinsartifactoryversioning

How to versionate artifacts on Artifactory without overwriting


I'm trying to extend our Jenkins job (which builds the entire project) to deploy the built artifacts to our Artifactory but then I faced some problems related to the versioning of the artifacts. If I try to redeploy an artifact whose version didn't change (not a snapshot), I get an error 403 (user 'foo' needs DELETE permission) which is understandable, I should not replace an already released artifact. If the artifact version contains -SNAPSHOT then there are no problems, it's always uploaded. My question is: how we should approach the scenario of having locked overwriting in Artifactory?

  • Shouldn't the artifactory plugin from Jenkins just ignore the deploy of the artifact in case is already deployed instead of failing the job?
  • Or should we use always -SNAPSHOT (during development) even the artifact has not changed?
  • Do we increase the version on every release even the artifact has not changed?

Solution

  • Shouldn't the artifactory plugin from Jenkins just ignore the deploy of the artifact in case is already deployed instead of failing the job?

    The job should fail if the artifact is already deployed with a fixed version (non -SNAPSHOT). For instance on a manual job trigger, I would like to know if I tried to build and deploy using a version name that is already published (maybe by someone else in the team)

    Or should we use always -SNAPSHOT (during development) even the artifact has not changed?

    -SNAPSHOT is made for development. Yes we usually push the artifact at the end of the build, even if it did not change because you updated for instance a README and the job was triggered.

    Usually SNAPSHOT have a lifetime depending on how you binary repository (here Artifactory) is configured. SNAPSHOT can be cleaned every 2 weeks for instance.

    The link shared by Manuel has other interesting definitions like

    Usually, only the most recently deployed SNAPSHOT,
    for a particular version of an artifact is kept in the artifact repository.
    Although the repository can be configured to maintain a rolling archive
    with a number of the most recent deployments of a given artifact
    

    https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm#MAVEN401

    Do we increase the version on every release even the artifact has not changed?

    yup we increase the version number at every release. I call release what the customer will get. Except an exceptional occasion, you wont go through the process of release if the artifact didn't change. A release usually involves a lot of people in an organization, even people that are not from Development. A popular standard is to use semantic versioning https://semver.org/ Sometime people prefer to version with the date. My advice is to use semver and have a file in the artifact with the date of the build. This file could be used by the artifact itself to tell its version at runtime.