0

I need to run a command like this:

atlassian confluence --action addLabels --labels labelName --space nameOfSpace --title "title name"

for a long list of titles. The command only accepts a single title argument and parameter.

Can I automate this using an Ant task that picks up a list of titles as input and puts each one in a command like the above and runs it?

I suppose I could just use replaceregexp to wrap each title in my list inside the above command, and put the whole thing into a bat file to run commands over and over, but isn't there a better way?

I've tried comma-separated lists of titles and other attempts to run a list in one command but it only seems to accept one at a time, and the documentation for the CLI says nothing about doing otherwise.

UPDATE:

I'd still be curious to know how to accomplish the above, but I finally found a way to do what I needed in one command. That is, to add or remove labels to pages in Confluence for all "child" pages of a given title by just entering the top page title:

confluence --action runFromPageList --space "SpaceName" --title "Parent Page Name" --descendents --common "--action addLabels --labels "New-Label-To-Add" --title ""@title@"" --space "SpaceName"" 

This is using the Confluence command line interface. The missing trick was to use -descendents (not --children, which is the way it's done in other confluence commands).

I had been extracting all child pages into a list-- that part I knew how to do -- and figured I'd go from there, but this way it automates the process using one command.

UPDATE II

As I mentioned above I found a way to add labels using one command in certain cases, but later I needed a way to add labels to a selected list of page titles (pages with no common parent). So I came back to this and used one of the answers here to devise a way to add labels by using for to loop over a list of titles in a .txt file. Here's what I ended up putting in my .bat file:

cmd /k for /F "usebackq delims=" %%A in (my.list.txt) DO (confluence --action addLabels --labels labelName --space spaceName --title "%%A")

One hitch was that the titles have spaces in the names, so I had to add "usebackq delims=" which I found in answer #2 here.

Community
  • 1
  • 1
user3762977
  • 651
  • 2
  • 15
  • 27
  • Have you the list of commands or you must extract from some place automatically? the batch `for` command can help you if is only loop from a string. – F.Rosado Aug 13 '14 at 16:39
  • It's just one command, the same command each time, with the parameter shown as "title name" the only thing changing, for each in list of titles. Can you demonstrate how the for command could do this? Thanks. – user3762977 Aug 13 '14 at 19:30

2 Answers2

1

You can use apply to run a command on a resource collection, like this:

<project name="project" default="addLabels">

<!-- comma-separated list of titles -->
<property name="titles" value='foo,"bar baz",etc' />

<target name="addLabels">
    <apply executable="atlassian" relative="true">
        <arg value="confluence" />
        <arg value="--action" />
        <arg value="addLabels" />
        <arg value="labelName" />
        <arg value="--space" />
        <arg value="nameOfSpace" />
        <arg value="--title" />
        <tokens>
            <string value="${titles}" />
            <stringtokenizer delims="," />
        </tokens>
    </apply>
</target>

Tested with Ant 1.9.2 and executable="echo", gives :

Buildfile: build.xml
    addLabels:
    [apply] confluence --action addLabels labelName --space nameOfSpace --title foo
    [apply] confluence --action addLabels labelName --space nameOfSpace --title "bar baz"
    [apply] confluence --action addLabels labelName --space nameOfSpace --title etc
BUILD SUCCESSFUL
grams
  • 649
  • 8
  • 8
0

Using batch command it's easy with the for command. A simple example :

for %%A in ("Title 1" "Title 2" "Title2") DO (
    atlassian confluence --action addLabels --labels labelName --space nameOfSpace --title %%A
)

The problem here is the readability if the list of titles is really large. A better solution is to have the process.cmd script and a file list.txt with all the titles. The final script will be:

@echo off
for /F %%A in (list.txt) DO (
   atlassian confluence --action addLabels --labels labelName --space nameOfSpace --title %%A

)
F.Rosado
  • 487
  • 4
  • 20