How to locate and modify the "Clean Working Directory" Job option, or the "Clean Working Directory" Task in bulk

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Under some circumstances, customers may have to review some Plan settings to validate if proper cleanup/hygiene tasks are enabled. On large Bamboo systems, it becomes impractical to do the research and change manually. This article demonstrates some strategies to modify the Bamboo Job's "Clean Working Directory" or the "Clean Working Directory" Task in bulk in Bamboo.

Environment

  • Bamboo DC
  • SQL database access

Diagnosis

Generate a report

Building SQL statements for reporting purposes is not part of the Atlassian Support scope and this work is provided "as-is", on a best-effort basis. Queries may work better or worse than expected, your mileage may vary. It is up to each customer to analyse each query individually and understand if that is enough for their specific needs.

The SQL statements below may not work due to a bug related to XML processing in Bamboo: BAM-22073 - Getting issue details... STATUS . If you encounter XML parsing errors while executing the queries, please work on replacing the XPATH/EXTRACTVALUE with simple functions such as LIKE. You may also use stored procedures to accomplish the same thing.

Run the following SQL statement against your Bamboo Database looking to have a report of the "Clean Working Directory" properties across your whole system.

The SQL below was tested on PostgreSQL. If you are using a different Database you may need to adapt the query to it. Please note that a temporary table TMP_BUILD_DEFINITION is created on the example below to overcome a known bug BAM-22073: Enabling a custom Artifact handler on a Plan breaks the XML on XML_DEFINITION_DATA:

DROP TABLE IF EXISTS TMP_BUILD_DEFINITION;

CREATE TEMPORARY TABLE TMP_BUILD_DEFINITION ON COMMIT DROP AS SELECT * FROM BUILD_DEFINITION;

UPDATE TMP_BUILD_DEFINITION SET XML_DEFINITION_DATA = REGEXP_REPLACE(XML_DEFINITION_DATA,
  ':(enabledForShared|enabledForNonShared|S3ArtifactHandler|ServerLocalArtifactHandler|BambooRemoteArtifactHandler|AgentLocalArtifactHandler|SftpArtifactHandler)',
    '', 'g');

SELECT B.FULL_KEY AS "Build_key",
    (XPATH('/configuration/cleanWorkingDirectory/text()', XML_DEFINITION_DATA::XML))[1]::TEXT AS "JobOtherCleanWorkingDirectory",
	CASE WHEN (XPATH('//taskDefinition[pluginKey="com.atlassian.bamboo.plugins.bamboo-artifact-downloader-plugin:cleanWorkingDirectoryTask"]/isEnabled/text()', 
                          XML_DEFINITION_DATA::XML))[1]::TEXT = 'true'
          THEN 'true'
          ELSE 'false'
    END AS "JobTaskCleanWorkingDirectoryTaskEnabled"
FROM 
    TMP_BUILD_DEFINITION BD
LEFT JOIN BUILD B ON B.build_id = BD.BUILD_ID
WHERE B.build_type IN ('JOB')

The expected output should look similar to this:

Build_keyJobOtherCleanWorkingDirectoryJobTaskCleanWorkingDirectoryTaskEnabled
FA-AGENT9-JOB1truefalse
BAM-BOO-SJfalsetrue
BAM-BOO-FJtruefalse
BAM-BOOT-JOB1falsefalse

Solution

Once you have a report, you can make a decision to modify the Plan configuration manually via the web interface, or depending on the volume of the changes or you can choose to modify your application in Bulk by following one of the paths below:

To modify a plan you have three supported ways:

  • Using Java Specs:
    1. Export each Plan to Java Specs format
    2. Modify the Plan to set the value of cleanWorkingDirectory at the Job or Task level
    3. Publish the changes back to Bamboo Server via Maven or an IDE
  • Using YAML Specs:
    • Make sure that YAML Specs is already in use by the Plan structure, otherwise modifying the Plans through this method may be challenging
    • Export each Plan to YAML Specs format or reach out to your Repository to modify it
    • Modify the YAML Specs' Plan structure to set the value of cleanWorkingDirectory at the Job or Task level
    • Push the changes to your Repository and monitor the changes in Bamboo
  • Use an Export/Import strategy:

    Note 1: Running export/import will overwrite the Bamboo instance completely, so test the process in a non-production environment before applying it in production. Depending on the size of your instance, this may become impractical due to the size of the exported file and the time it will take for the process to complete.

    Note 2: Atlassian does not support or recommend modifying the Database directly. If you intend to alter the DB directly, make sure you have a complete backup of the Database before making any updates and double-check if the application is not running. If you have any issues from modifying the Bamboo DB directly, we'd ask you to roll back to the last valid backup.

    1. Export data for backup
    2. Extract the zip file
    3. Modify the XML text files and set the value of cleanWorkingDirectory at the Job or Task level
    4. Create the zip file again
    5. Import data from backup


Last modified on Mar 4, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.