The following use cases demonstrate common uses for the FileOps plugin.
Perform common file operations
In this example, you perform several operations:
-
Create a directory.
-
Create files in the directory.
-
Create an archive from the directory.
-
Delete the directory.
-
Open the archive file.
Set up a use case project and procedure
Create a project, procedure, and parameter in the procedure:
-
Create a project called
Use Cases
. -
In the
Use Cases
project, create a procedure calledUse Case CommonFileOps
. -
For
Use Case CommonFileOps
, create a new parameter calledbasedir
with the following values:-
Name:
basedir
-
Type: Text entry
-
Required? (Checkbox): Checked
You can leave all other fields blank.
-
Create directories
To use the FileOps plugin to create a directory:
-
Create a step named
Create Directory
and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the CreateDirectory procedure.
-
Populate the Input Parameters field Path as
$[basedir]/directory
.
Create files in a directory
To use the FileOps plugin to create files in a directory:
-
Create a new step named
Create FirstFile
and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the CreateEmptyFile procedure.
-
Populate the Input Parameters fields:
-
Name:
$[basedir]/directory/file1.txt
-
Permission Mode: Leave blank
-
-
Create a copy of the previous step, and name it
Create SecondFile
. -
Populate the Input Parameters fields:
-
Name:
$[basedir]/directory/file2.txt
-
Permission Mode: Leave blank
-
Create an archive of a directory
To use the FileOps plugin to create an archive file of a directory:
-
Create a new step named
Zip Directory
and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the Create Zip File procedure.
-
Populate the Input Parameters fields as follows:
-
Source Path:
$[basedir]/directory
-
Zip File:
$[basedir]/directory.zip
-
Delete a directory
To use the FileOps plugin to delete a directory:
-
Create a new step called
Delete Directory
and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, then select the DeleteDirectory procedure.
-
Populate the Input Parameters fields as follows:
-
Source Path:
$[basedir]/directory
-
Recursive (Checkbox): Checked
-
Unzip a directory
To use the FileOps plugin to unzip a directory:
-
Create a new step named
UnZip Directory
and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the Unzip File procedure.
-
Populate the Input Parameters fields as follows:
-
Zip File:
$[basedir]/directory.zip
-
Destination Directory:
$[basedir]
-
Use case summary
If you followed all the sections in this use case, your procedure should be similar to:
Execute the procedure and provide a directory path for the basedir
parameter. In the following image, /tmp
directory is used:
For Windows machines, change the basedir parameter to a Windows path such D:/ .
|
After running the procedure, you should be able to see something similar to:
This procedure is portable, and you can reuse it as needed.
Download and verify a file from the internet
In this example, you will create a procedure to download a file from internet and compare its checksum with the following procedures:
-
Download a file from the internet, such as an Ant binary.
-
Download the file’s checksum.
-
Compare the file with the checksum.
Set up a use case project and procedure
Create a project, procedure, and parameter in the procedure:
-
If you do not already have one, create a project called
Use Cases
. -
In the
Use Cases
project, create a procedure calledUse Case VerifyFile
. -
For
Use Case VerifyFile
, create a new parameter calledbasedir
with the following values:-
Name:
basedir
-
Type: Text entry
-
Required? (Checkbox): Checked
You can leave all other fields blank.
-
Download a file and its checksum
You can use the Command task type to implement executable commands into your pipelines. To create a command step to download the use case file and checksum:
-
Create a new step named Download Ant and its checksum and select Definition.
-
For Task type, select the Command option.
-
In the Command field, to get the binary and checksum enter:
wget https://archive.apache.org/dist/ant/ant-current-bin.zip \ https://archive.apache.org/dist/ant/ant-current-bin.zip.md5
-
In the Working Directory field, enter
$[basedir]
to use the parameter created previously. -
Fill the other fields as shown in the following image:
Figure 4. Download Ant command procedure input parameters
Compare checksum values
To use the FileOps plugin to compare checksums:
-
Create a new step, name it
Read Checksum
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the SaveFileContent procedure.
-
Fill the fields as follows:
-
Path:
$[basedir]ant-current-bin.zip.md5
-
Content (output property path):
/myjob/md5
-
-
Create a new step, name it
Validate Checksum
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the Validate Checksum procedure.
-
Fill the fields as follows:
-
File:
$[basedir]ant-current-bin.zip
-
Checksum Type:
MD5
-
Expected Checksum:
$[/myjob/md5]
-
Use case summary
If you followed the sections in this use case, your procedure should be simular to:
Run the procedure and provide a path for the basedir field. The following images uses /tmp
.
For Windows machines, change the basedir parameter to a Windows path such D:/ .
|
After running the procedure we should see something like:
Job properties:
Perform a file diff
In this example, you create a procedure to find the differences between two files, with the following procedures:
-
Create two different files.
-
Compare the content in the two files and create a log showing the differences.
Set up a use case project and procedure
-
Create a project called
Use Cases
. -
In the
Use Cases
project, create a procedure calledUse Case FileDiff
. -
For
Use Case FileDiff
, create a new parameter calledbasedir
with the following values:-
Name:
basedir
-
Type: Text entry
-
Required? (Checkbox): Checked
-
Create files and add text
To create a file and add text to it:
-
Create a new step named
FirstFile
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the AddTextToFile procedure.
-
Populate the Input Parameters fields as follows:
-
Path:
$[basedir]/file1.txt
-
Append Mode (Checkbox): Leave unchecked
-
Add new line to the end (Checkbox): Checked
-
Content:
This is the first line.
-
-
Create a copy of the previous step, and name it
SecondFile
. -
In the Input Parameters, change the fields Path and Content as shown in the following image:
-
Path:
$[basedir]/file1.txt
-
Append Mode (Checkbox): Leave unchecked
-
Add new line to the end (Checkbox): Checked
-
Content:
This is the first line. This is the second line.
-
Compare files
To compare two files:
-
Create a new step named
Diff Files
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the DiffFiles procedure.
-
Populate the Input Parameters fields as shown in the following image:
-
First File:
$[basedir]/file1.txt
-
Second File:
$[basedir]/file2.txt
-
Display Format: Table
You can rerun the step using different display formats to find which you prefer.
-
Use case summary
If you followed the sections in this use case, your procedure should be simular to:
Run the procedure and provide a path for the basedir field. The following images uses /tmp
.
For Windows machines, change the basedir parameter to a Windows path such D:/ .
|
You can check the results on the Job Details page:
To see the result of the file diff, open the log file for Diff files:
Encrypt and decrypt files
In this example, you encrypt and decrypt a file with the following steps:
-
Choose the file to encrypt and decrypt.
-
Encrypt the file.
-
Decrypt the file.
Prerequisites
-
Create a
/tmp
directory. -
Create a file named
file.txt
with the following text:This is the first line. This is the second line.
-
Save the file in the
/tmp
directory.
Set up a use case project and procedure
Set up a project and procedure to encrypt and decrypt the file:
-
Create a project called
Use Cases
. -
In the
Use Cases
project, create a procedure calledUse Case FileCrypt
.
Encrypt files
To encrypt files:
-
Create a new step named
Encrypt File
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the Crypt procedure.
-
Populate the Input Parameters fields as follows:
-
File:
/tmp/file.txt
-
Action (Dropdown): Decrypt
-
Key: Enter a key you.
Ensure you make a note of the key you enter. You must use this same key in the Decrypt files step. -
BackUp file (Checkbox): Optional
-
-
Run the procedure and open the log file in the browser:
Figure 13. File encryption job log -
To ensure the file was encrypted, use
cat file.txt
to print the file in your console:Figure 14. Encrypted file cat example
Decrypt files
To decrypt files:
-
Create a new step named
Decrypt File
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the Crypt procedure.
-
Populate the Input Parameters fields as follows:
-
File:
/tmp/file.txt
-
Action (Dropdown): Decrypt
-
Key: Enter the same key you used in the Encrypt files step.
-
BackUp file (Checkbox): Optional
-
Run the procedure and open the log file in the browser:
To ensure the file was decrypted, use cat file.txt
to print the file in your console:
Sync two directories
In this example, the contents of two directories are synchronized.
Prerequisites
Create two folders with several files each. For the best examples, it is recommended:
-
Some files should be the same name and content.
-
Some files should have the same name but different content.
-
Some files should exist in only one of the folders.
Set up a use case project and procedure
To set up the sync folders procedure:
-
Create a project called
Use Cases
. -
In the
Use Cases
project, create a procedure calledUse Case SyncFolders
.
Sync the directories
To sync the directories:
-
Create a new step named
Sync Folders
, and select Definition. -
For the procedure Task type, select Plugin.
-
From the plugin Select category dropdown menu, select Utility.
-
From the Select plugin dropdown menu, select the EC-FileOps plugin, and then select the SyncFolders procedure.
-
Populate the Input Parameters fields as shown in the following image:
-
First Directory:
/tmp/directory1
-
Second Directory:
/tmp/directory2
-
Sync Rule: Keep First
All other fields may be left blank.
Alternatively, you can select the Dry run parameter to simulate the actions that would be executed when the procedure runs. Dry runs are designated in the job log:
Figure 17. SyncFolders procedure dry run log
-
When you run the procedure, the step creates a log with the actions that were performed.