Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-73793

Build Retention does not delete artifacts for Artifactory versions > 7.68.14

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • artifactory-plugin
    • None
    • Jenkins 2.387.1
      artifactory-plugin: 4.0.0

      We encountered the problem, that build artifacts are not deleted for Artifactory versions > 7.68.14 when build retention is applied. 

      We also have a support case open at JFrog regarding a similar issue and the problem here is, that the implementation in Artifactory changed. 

      In versions up to 7.68.14, the build artifacts have been matched to the build by comparing the properties "build.name" and "build.number". For newer versions, the additional property "build.timestamp" of the artifacts is compared to the start timestamp stored in the BuildInfo. 

      As the plugin is storing different timestamps in the build info and as artifact properties, the retention does not work anymore. 

      As a workaround, we can override the build info timestamp in the pipeline before publishing like

      def buildInfo = Artifactory.newBuildInfo()
      buildInfo.setStartDate(currentBuild.build().getTimestamp().getTime())

      I guess that this is cause by the fact, that the BuildInfo is initialized by the current time  when created: https://github.com/jenkinsci/artifactory-plugin/blob/73be393da5913343dd55e0ca5b09cab864930abb/src/main/java/org/jfrog/hudson/pipeline/common/types/buildInfo/BuildInfo.java#L60

      But the artifact properties are defined with the start time of the jenkins build: https://github.com/jenkinsci/artifactory-plugin/blob/73be393da5913343dd55e0ca5b09cab864930abb/src/main/java/org/jfrog/hudson/pipeline/common/Utils.java#L407

       

      For tracing the issue in Artifactory, it is helpful to adjuste the logger config in "$JFROG_HOME/artifactory/var/etc/artifactory/logback.xml" and add the following section

      <appender name="build-delete" class="ch.qos.logback.core.rolling.RollingFileAppender">
          <File>${log.dir}/artifactory-build-delete.log</File>
          <rollingPolicy class="org.jfrog.common.logging.logback.rolling.FixedWindowWithDateRollingPolicy">
            <FileNamePattern>${log.dir.archived}/artifactory-build-delete.%i.log.gz</FileNamePattern>
            <maxIndex>10</maxIndex>
          </rollingPolicy>
          <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>25MB</MaxFileSize>
          </triggeringPolicy>
          <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="org.jfrog.common.logging.logback.layout.BackTracePatternLayout">
              <pattern>%date{yyyy-MM-dd'T'HH:mm:ss.SSS, UTC}Z [jfrt ] [%-5p] [%-16X{uber-trace-id}] [%-30.30(%c{3}:%L)] [%-20.20thread] - %m%n</pattern>
            </layout>
          </encoder>
        </appender>
        <logger name="org.artifactory.build" additivity="false">
          <level value="trace"/>
          <appender-ref ref="build-delete"/>
        </logger> 

      You will find log outputs in the file artifactory-build-delete.log like

      Executing Artifacts search for build <build-name>:<build-number>:<build-timestamp>
      Search returned 0 artifacts 

      As 0 artifacts the build itself will be deleted leaving unlinked artifacts in the repository

            eyalbe Eyal Ben Moshe
            prewashed Stefan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: