# Limit the number of  builds stored in Artifactory

**URL:** <https://community.jenkins.io/t/limit-the-number-of-builds-stored-in-artifactory/1172>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [January 6, 2022, 9:10am UTC](https://community.jenkins.io/t/limit-the-number-of-builds-stored-in-artifactory/1172 "2022-01-06T09:10:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bspteam](https://avatars.discourse-cdn.com/v4/letter/b/a6a055/32.png) [@bspteam](https://community.jenkins.io/u/bspteam)\
**Post date:** [January 6, 2022, 9:10am UTC](https://community.jenkins.io/t/limit-the-number-of-builds-stored-in-artifactory/1172/1 "2022-01-06T09:10:56Z")

</div>

Hello Team,

I am trying to implement on my existing pipeline to limit the number of build stored in artifactory however it is not working .

A “log rotation” strategy should be implemented in the Jenkins pipeline to only store the last 5 builds This change should be made in the pipeline script itself .

```auto
    stage("Artifactory Upload") {
		def directory = "generic-local/ABC/XYZ/${params['version']}/${currDate}/${buildNo}/"
		def server = Artifactory.server 'art-int'
		
		def upload_spec_bin = """{
			"files": [
				{
					"pattern": "*",
					"target": "${directory}",
					"exclusions": ["*.txt"]
				}
			]
		}"""

		build_info = server.upload spec: upload_spec_bin
		build_info.retention maxBuilds: 5,deleteBuildArtifacts: true
		server.publishBuildInfo build_info
	}
```

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [January 6, 2022, 9:18am UTC](https://community.jenkins.io/t/limit-the-number-of-builds-stored-in-artifactory/1172/2 "2022-01-06T09:18:18Z")

</div>

Is your posted code pseudo code of what your trying to do?  
Or is it failing to do what you want it to do? Is there an error message of some sort?

Wouldn’t retention be something that artifactory itself configure (I’ve never admined artifactory before)

I’m not sure what your “question” is.

---

<div class="post-metadata">

**Author:** ![bspteam](https://avatars.discourse-cdn.com/v4/letter/b/a6a055/32.png) [@bspteam](https://community.jenkins.io/u/bspteam)\
**Post date:** [January 6, 2022, 10:24am UTC](https://community.jenkins.io/t/limit-the-number-of-builds-stored-in-artifactory/1172/3 "2022-01-06T10:24:11Z")

</div>

Hello,

Yes its code that i am trying but it is not working as expected.  
My expectation is to delete old build from artifactory using my jenkin pipeline.

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [January 6, 2022, 8:58pm UTC](https://community.jenkins.io/t/limit-the-number-of-builds-stored-in-artifactory/1172/4 "2022-01-06T20:58:41Z")

</div>

> [@bspteam](#):
>
> Yes its code that i am trying but it is not working as expected.

what is it doing then?
