Skip to main content

Tasks

Configuring and Executing Tasks

The repository manager allows you to schedule the execution of maintenance tasks. The tasks can carry out regular maintenance steps that will be applied to all repositories or to specific repositories on a configurable schedule or simply perform other system maintenance. Use the Tasks menu item in the System section of the Administration menu to access the feature view, shown in Figure: “Managing Tasks”, to manage your tasks.

User accounts with the nx-admin or nx-tasks privileges can access this menu item.

53412656.png

Figure: Managing Tasks

The list interface allows you to add new tasks with the Create task button as well as inspect and work with the configured tasks. The list shows the following columns:

Name

A user-defined name for the task to identify it in the user interface and log files.

Type

The type of action the scheduled task executes. The list of available task types is documented in more detail below.

Status

Tasks can either be Waiting for their next run, currently Running or Disabled.

Schedule

The Schedule column shows the Task frequency e.g., Daily, Monthly, Manual, and others.

Next run

This column displays date and time of the next execution of the task based on the configured schedule.

Last run and Last result

These columns display the date and time as well as the result and duration of the last execution of the specific task.

When creating or updating a scheduled task, you can configure the following additional properties:

Task enabled

Enable or disable a specific task with the checkbox.

Notification Email

Configure a notification email for the task execution. If a scheduled task meets the notification condition configured below, a notification email will be sent to the configured email recipient. In the case of a failure, the notification will contain the task identifier and name as well as the stack trace of the failure. Otherwise, a summary of the task execution, including the start time and duration, will be sent.

Notification Condition

Notifications can be sent on Failure or on Success or Failure. If Failure is selected, a notification email will be sent only if the task ends abnormally.

Task frequency

Selecting the task frequency allows you to configure the schedule for the task executions. Available choices are Manual, Once, Hourly, Daily, Weekly, Monthly, and Advanced (provide a CRON expression). Apart from Manual, all choices trigger display of a custom user interface for scheduling the specific recurrence. Weekly scheduling requires at least one day of the week to be selected. The advanced setting allows you to provide a CRON expression to configure more complex schedules.

The syntax used for Advanced (provide a CRON expression) follows the UNIX-style CRON syntax. CRON expressions are comprised of 6 required fields and one optional field separated by white space as described in Table 4.1, “Fields of a CRON Expression from Left to Right” and the following paragraphs. A simple expression example is 0 0 9 * * ?. This configuration triggers a task execution every day at 9:00 in the morning. Further examples are available in Table 4.2, “CRON Expression Examples”.

Field Name

Allowed Values

Allowed Special Characters

Seconds

0-59

, - * /

Minutes

0-59

, - * /

Hours

0-23

, - * /

Day-of-month

1-31

, - * ? / L W

Month

1-12 or JAN-DEC

, - * /

Day-of-Week

1-7 or SUN-SAT

, - * ? / L #

Year (Optional)

empty, 1970-2099

, - * /

Table 4.1. Fields of a CRON Expression from Left to Right

*

This character is used to specify any value. For example, * in the minute field means every minute.

?

This character is allowed for the day-of-month and day-of-week fields. It is used to specify no specific value. This is useful when you need to specify something in one of the two fields, but not the other.

-

This character is used to specify ranges. For example 10-12 in the hour field means "the hours 10,11 and 12".

,

This character is used to specify additional values. For example MON,WED,FRI in the day-of-week field means "the days Monday, Wednesday, and Friday".

/

This character is used to specify a start value and increments. For example "0/15" in the seconds field means "the seconds 0, 15, 30, and 45". And "5/15" in the seconds field means "the seconds 5, 20, 35, and 50". Specifying * before the / is equivalent to specifying 0 as the value to start with. Essentially, for each field in the expression, there is a set of numbers that can be turned on or off. For seconds and minutes, the numbers range from 0 to 59. For hours 0 to 23, for days of the month 0 to 31, and for months 1 to 12. The / character simply helps you turn on every "nth" value in the given set. Thus "7/6" in the month field only turns on month "7", it does not mean every 6th month, please note that subtlety.

L

This character is allowed for the day-of-month and day-of-week fields. This character is short-hand for "last", but it has different meaning in each of the two fields. For example, the value L in the day-of-month field means "the last day of the month" - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means 7 or SAT. But if used in the day-of-week field after another value, it means "the last xxx day of the month" - for example 6L means "the last Friday of the month". When using the L option, it is important not to specify lists, or ranges of values, as you will get confusing results.

W

This character is allowed for the day-of-month field. This character is used to specify the weekday (Monday-Friday) nearest the given day. As an example, if you were to specify "15W" as the value for the day-of-month field, the meaning is: "the nearest weekday to the 15th of the month". So if the 15th is a Saturday, the trigger will fire on Friday the 14th. If the 15th is a Sunday, the trigger will fire on Monday the 16th. If the 15th is a Tuesday, then it will fire on Tuesday the 15th. However if you specify 1W as the value for day-of-month, and the 1st is a Saturday, the trigger will fire on Monday the 3rd, as it will not jump over the boundary of a months days. The W character can only be specified when the day-of-month is a single day, not a range or list of days.

Tip

The L and W characters can also be combined for the day-of-month expression to yield LW, which translates to "last weekday of the month".

#

This character is allowed for the day-of-week field. This character is used to specify "the nth" XXX day of the month. For example, the value of "6#3" in the day-of-week field means the third Friday of the month (day 6 = Friday and #3 is the 3rd one in the month). Other examples: 2#1 is the first Monday of the month and 4#5 is the fifth Wednesday of the month. Note that if you specify #5 and there is not 5 of the given day-of-week in the month, then no firing will occur that month.

Note

The legal characters and the names of months and days of the week are not case sensitive.

Expression

Description

0 0 12 * * ?

Fire at 12pm (noon) every day

0 15 10 ? * *

Fire at 10:15am every day

0 15 10 * * ?

Fire at 10:15am every day

0 15 10 * * ? *

Fire at 10:15am every day

0 15 10 * * ? 2015

Fire at 10:15am every day during the year 2015

0 * 14 * * ?

Fire every minute starting at 2pm and ending at 2:59pm, every day

0 0/5 14 * * ?

Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day

0 0/5 14,18 * * ?

Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day

0 0-5 14 * * ?

Fire every minute starting at 2pm and ending at 2:05pm, every day

0 10,44 14 ? 3 WED

Fire at 2:10pm and at 2:44pm every Wednesday in the month of March.

0 15 10 ? * MON-FRI

Fire at 10:15am every Monday, Tuesday, Wednesday, Thursday and Friday

0 15 10 15 * ?

Fire at 10:15am on the 15th day of every month

0 15 10 L * ?

Fire at 10:15am on the last day of every month

0 15 10 ? * 6L

Fire at 10:15am on the last Friday of every month

0 15 10 ? * 6L 2002-2005

Fire at 10:15am on every last Friday of every month during the years 2002, 2003, 2004 and 2005

0 15 10 ? * 6#3

Fire at 10:15am on the third Friday of every month

Table 4.2. CRON Expression Examples

The Start date and Start time allow you to configure a specific date and time from when the schedule should be activated. The Time to run this task settings is used to configure the actual time of the task execution.

Task-type specific configuration is displayed below the notification email input field and differs for each scheduled task.

Types of Tasks and When to Use Them

Warning

Tasks with the prefix "Repair -" are only intended to be run if you are having specific trouble with your system. These tasks should only be run manually, not scheduled, and should usually only be run at the advice of a Sonatype staff member.

The following tasks are available:

Task Name

Task Id

Description

Typically Scheduled

Admin - Backup H2 Database (Pro only)

h2.backup.task

For those using an embedded H2 database, this task performs a full backup of the underlying config, security, and component databases - not blobstore content.

You must choose a location for the backup data for this task. When you run the backup, the task adds a timestamp to the backup files that are created in the backup data location. It is important to note this task does not backup actual repository content.

Be aware that while the task is running, the repository will temporarily be put into a read-only state.

Yes

Admin - Cleanup repositories using their associated policies

repository.cleanup

This task is automatically created on start of a server that has cleanup abilities.

When run, this task will execute cleanup of all the repositories that have a policy other than None set. There is no partial execution. This task cannot be manually created and either runs or does not.

By default, this task is scheduled to run daily at 1AM server time. This task can be edited, disabled, and executed manually if desired. Nexus Repository will automatically recreate this task on server restart if you delete it.

See Cleanup Policies for more information.

Yes (automatically scheduled)

Admin - Cleanup Tags (Pro only)

tags.cleanup

This task will allow you to cleanup tags once they reach a certain age, haven't been modified in a certain period, or using a regular expression on the name.

You can also choose to delete the components along with those tags, as well as restrict this component deletion to a particular format or repository.

See additional details on the tagging page.

Yes

Admin - Cleanup unused asset blobs (Pro only)

assetBlob.cleanup

This is a background task that soft deletes unused blobs to prevent Nexus Repository from accidentally creating multiple blobs associated with the same asset.

Note that altering the frequency at which this task runs can impact whether or not the Admin - Compact blob store task listed below is able to free up storage space. The Admin - Compact blob store task only hard deletes items that have been soft deleted.

This task is only for those using H2 or PostgreSQL databases.

By default, Nexus Repository automatically creates one Admin - Cleanup unused asset blobs task for each format and schedules them to run every 30 minutes from when Nexus Repository is booted. No user action is required.

Yes

Admin - Compact blob store

blobstore.compact

Content deleted from a blob store is not physically deleted from the storage device. Instead it is only internally marked for deletion. This task performs the actual deletion of the relevant files, and therefore frees up the storage space.

Note

This only affects blob store of type File. S3 type blob stores are cleaned up using AWS Lifecycle.

Yes

Admin - Change repository blob store (Pro only)

repository.move

Note

The Admin - Change repository blob store task is a Pro-only feature and requires a PostgreSQL or H2 database and Sonatype Nexus Repository version 3.58.0+.

This task can be used to change a repository blob store. See Change repository blob store for more details.

No

Admin - Delete blobstore temporary files

blobstore.delete-temp-files

Deletes all temporary files (.bytes and .properties) stored in the selected blobstore's /content/tmp directory. Only file blob stores are processed.

Optional

Admin - Delete orphaned API keys

security.purge-api-keys

This task deletes old, unused API keys. These keys are generated, for example, when using the User Token feature and become orphaned when the associated user account is deleted.

Yes

Admin - Export databases for backup

db.backup

For those using OrientDB, this task performs a full backup of the underlying config, security, and component databases - not blobstore content.

You must choose a location for the backup data for this task. When you run the backup, the task adds a timestamp to the backup files that are created in the backup data location. It is important to note this task does not backup actual repository content.

Be aware that while the task is running, the repository will temporarily be put into a read-only state.

Yes

Admin - Execute script

script

Scripts can be provided in the Source field and have to be written using the Groovy programming language. These scripts can use the APIs of the repository manager to perform maintenance and other modification tasks. Please consult related documentation for writing scripts and additional information/references to the Javadoc and source.

As of version 3.21.2 and to improve security, this task and the ability to create it are disabled by default. It is a security best practice to keep scripting disabled. However, if you need to enable it, follow the instructions for enabling scripting in the Script API topic.

When scripting is disabled, you will see a notice reading "Admin - Execute script task creation is disabled" at the top of the screen where you select a new task type to create. You will also not be able to add a new script or update existing scripts via the REST API; affected resources will respond with an HTTP status line of "410 Gone," and the response body will contain a message that "Creating and updating scripts is disabled."

Optional

Admin - Log database table record counts (Pro only)

cluster.periodicLogging

This task logs clustered database record counts for each node. The task is automatically added when clustering is enabled and can be disabled by including an additional property in the nexus.properties file:

nexus.log.cluster.enabled=false

Yes

Admin - Remove a member from a blob store group

blobstore.group.memberRemoval

This task removes a blob store from a group. Each blob within the removed store is written back to the group and then deleted from the removed blob store.

No

Apt - Rebuild Apt metadata

repository.apt.rebuild.metadata

This task rebuilds the metadata for a chosen Apt hosted repository.

No

Docker - Delete incomplete uploads

repository.docker.upload-purge

This task cleans up orphaned files that may exist in temporary storage as result of a restart or incomplete/interrupted uploads.

The Age in hours parameter allows you to configure the minimum age of incomplete uploads to be deleted.

Yes

Docker - Delete unused manifests and images

repository.docker.gc

This task will handle deletion of content that is no longer referenced, images that are no longer referenced by a tagged manifest and V1 layers that are no longer referenced by a tagged layer.

Yes

Helm - Rebuild Helm metadata

repository.helm.rebuild.metadata

This task rebuilds the metadata for a chosen Helm hosted repository.

No

Maven - Delete SNAPSHOT

repository.maven.remove-snapshots

This task deletes SNAPSHOT components from a Maven repository based on a configured number of SNAPSHOTs, age, and release version. See Maven SNAPSHOT Tasks for full information.

Yes

Maven - Delete unused SNAPSHOT

repository.maven.purge-unused-snapshots

We have replaced this task with the Cleanup Policies feature. We have preserved information about this task for those still using it; however, as a best practice, you should use the cleanup feature instead of this task. This task deletes SNAPSHOT components from a Maven repository based on the number of days it has been since the component was last requested. See Maven SNAPSHOT Tasks for full information.

Yes

Maven - Publish Maven Indexer files

repository.maven.publish-dotindex

The task publishes the indexer files for all or a specific Maven repository.

Optional

Maven - Unpublish Maven Indexer files

repository.maven.unpublish-dotindex

This task is the counterpart to the task Maven - Publish Maven Indexer files and can remove the indexer files.

Optional

Repair - Rebuild Maven repository metadata (maven-metadata.xml)

repository.maven.rebuild-metadata

This task rebuilds the maven-metadata.xml files with the correct information and will also (optionally) validate and fix any incorrect checksums (.md5/.sha1) for all files in the specified maven2 hosted repository. The Group Id, Artifact Id and Base Version parameters allow you to narrow down the section of the repository that will be repaired. Note that maven-metadata.xml files are normally maintained by the deploying clients (e.g., maven, gradle, ivy) per the maven repository protocol, and also by Nexus Repo when artifacts are deleted from repositories. This task should never be run on a regular basis, it should only be run manually in rare cases to repair a corrupted repository.

No

PyPI - Delete index Asset MD5 Metadata

repository.pypi.rebuild-metadata

This task deletes index assets with MD5 checksums on their links from the selected PyPI repositories. Note that this only removes the index, not the checksum.

No

PyPI - Delete legacy proxy assets

repository.pypi.delete-legacy-proxy-assets

This task deletes old assets that were previously duplicated due to a code-path change.

No

PyPI - Generate Missing SHA256 Checksums

repository.pypi.generate-missing-sha256-checksums

This task generates sha256 checksums for those PyPI assets that are missing a sha256 checksum.

No

Repair - Rebuild repository browse

create.browse.nodes

This task rebuilds the tree browsing data based upon current information in the database.

No

Repair - Rebuild repository search

repository.rebuild-index

With support for hosted and proxy repositories, this task rebuilds the search index. It inspects actual components and assets found in the selected repository and thus reflects the true content for supporting search and browse actions.

Note

Cancelling this task before completion could result in apartially rebuilt search indexshowing incomplete componentsearch results until it isrun againand allowed to complete.

No

Repair - Reconcile component database from blob store

blobstore.rebuildComponentDB

This task allows you to recover lost asset/component metadata from a chosen blob store. The task is useful in cases where you have restored from backup, and the database and blob storage may be out of sync. This task should never be executed during normal operation of the server. When executed, the task searches the selected blob store for blobs missing their associated metadata. The asset/component metadata is restored based on the information contained in the blob store.

You can configure the task to only reconcile blobs created in last specified number of days. This can drastically reduce your recovery time.

Note

For file blob stores, do not set this number to anything over 90 days. This is the maximum that Sonatype Nexus Repository can recover for file blob stores.

Currently, this task only recovers metadata for:

  • Apt

  • Docker

  • Go

  • Helm

  • Maven

  • npm

  • NuGet

  • p2

  • PyPI

  • R

  • Raw

  • RubyGems

  • Yum

Warning

npm and Yum search and tree view browsing will not work after running this task unless you run the respective metadata repair tasks ( Repair - Reconcile npm /-/v1/searchmetadata and Repair - Rebuild Yum repository metadata (repodata) ) first. Builds will work however.

Running these tasks before restore is complete will likely cause incomplete search and browse results.

NOTE: To avoid resultant possible errors in search and browse, we recommend running Repair - Rebuild repository browseand Repair - Rebuild repository search tasks when your component database repair is complete.

No

Repair - Reconcile date metadata from blob store

rebuild.asset.uploadMetadata

In version 3.2.1 and earlier, it was possible to have uploaded asset records missing the creation date. This task was introduced in 3.6.1 specifically to read creationTime, createdBy and createdByIP values from asset blob properties files and update the affected asset records in the database. Asset records will only get updated if the asset record createdBy value is not set at all, otherwise asset records will not be modified by this task.

It is not recommended to run this task except under the following conditions:

  • Nexus Repository version 3.2.1 OR earlier was in use at one time and has been upgraded

  • an asset record already exists in the database

  • the asset record createdBy user is not set

  • the blob ref for that asset can be found in the blobstore

No

Repair - Reconcile npm /-/v1/searchmetadata

repository.npm.reindex

This task extracts search metadata from all npm packages in all npm hosted repositories to enable support for the new /v1/ search endpoint that replaced the /all/ endpoint.

No

Repair - Rebuild npm metadata

repository.npm.rebuild-metadata

This task rebuilds the metadata for a chosen npm hosted repository and can serve as a recovery tool in cases where the npm metadata has been corrupted. The task can rebuild metadata for all packages in the repository or only for a specified package.

No

Repair - Rebuild Yum repository metadata (repodata)

repository.yum.rebuild.metadata

This task rebuilds the metadata for a chosen Yum hosted repository. This task runs automatically 60 seconds (configurable) after an RPM is uploaded, deleted or redeployed.

No

Replication - Backfill blob store attributes with component metadata (Pro only)

replication.blobattributesbackfill

This task adds necessary metadata to any existing blobs. When this task finishes running, all existing blobs’ metadata has been populated in the properties files and are ready to be replicated. You should wait until this task finishes running before configuring a replication connection.

No

Repository - Delete unused components

repository.purge-unused

This task can be used to delete components and assets in proxy repositories. Any component that has not been requested in the configured number of days will be soft-deleted. The underlying soft-deleted blobs are permanently deleted using the strategy supported by the blobstore implementation.

Older instances would typically schedule this but this is effectively replaced by the Cleanup feature.

No

Repository - Import external files (Pro only)

repository.import

This task can be used to import external content into a Nexus Repository Manager instance. The external content must be laid out in the proper directory structure for the desired repository format. See Repository Import for more details.

No

Repository - Export assets (Pro only)

repository.export

This task can be used to export content from a repository. See Repository export for more details.

No

Rubygems - Generate SHA256 Checksums

repository.rubygems.generate-sha256-checksums

This task generates sha256 checksums for those RubyGem assets that are missing a sha256 checksum.

No

Repair - Rebuild Rubygems versions file

repository.ruby.rebuild.versions

Task to rebuild the /versions file in hosted RubyGems repositories. This task should never be run on a regular basis; it should only be run manually in rare cases to repair a corrupted repository.

No

Statistics - Recalculate vulnerabilities statistics

repository.vulnerability.statistics

This task provides the Log4j Visualizer with request log data. When run, it deletes the existing data that the visualizer is using and re-processes the logs. See Log4j Visualizer for more details.

Yes

A third-party plugin may provide additional scheduled tasks which will appear once you have installed the plugin.

Setting up task execution adapted to your usage of the repository manager is an important first step when setting up a Nexus Repository Manager instance. It is also important to update your tasks when changing your usage patterns. For example, adjustments to your tasks may be required if you start to regularly deploy snapshots by introducing continuous integration server builds with deployment.

Task Logging

The output of every task run will go to a separate log file. By default these task logs are stored in $data-dir/log/tasks. The file name of each task log is the type followed by the full date and time the task started. For example: repository-maven.purge-unused-snapshots-20170618153235.log.

Generally the output of the task will go to both the nexus.log and the specific task log, however some tasks will only go to the nexus.log.

For long running tasks, progress will be logged back to the nexus.log every 10 minutes as the work continues. Most commonly this will appear as a contextual update relevant to that particular task such as the number of items that have been processed, updated, deleted, etc.

Task log files are removed after 30 days.