Creating a script asset with CPDCTL in watsonx.ai Runtime
Learn to create a script asset with the CPDCTL command line interface.
-
Install the CPDCTL library.
CPDCTL_VERSION = "" ! curl -L https://github.com/IBM/cpdctl/releases/download/{CPDCTL_VERSION}/cpdctl_linux_amd64.tar.gz --output cpdctl_linux_amd64.tar.gz
Check for the available versions on the GitHub releases page.
-
Extract the downloaded archive.
! tar xzf cpdctl_linux_amd64.tar.gz
-
Ensure that the
cpdctl
archive is in the current working directory and the system PATH.%%capture %env PATH={CWD}:{PATH}
-
Check that the CLI is accessible.
! cpdctl version
-
Optional: The following steps are not required if you are running the script in a Cloud Pak for Data environment runtime.
URL = "<<CPD URL>>" USERNAME = "<<CPD user name>>" APIKEY = "<<CPD user API key>>" ! cpdctl config context cpd-demo --url {URL} --username {USERNAME} --apikey {APIKEY} project_id = os.getenv('PROJECT_ID')
-
Open your script.
with open('<test_script>', 'w') as f: f.write("echo OK")
-
Create script asset.
! cpdctl asset script create --file <test_script> --project-id {project_id}
When you run this line of code, you receive the asset ID in its output.
-
List the script assets in the project.
! cpdctl asset search --type-name script --query 'test.sh' --project-id {project_id}
-
Optional: You can delete the script with the following code.
SCRIPT_ASSET_ID = "" ! cpdctl asset delete --asset-id {SCRIPT_ASSET_ID} --project-id {project_id}
Parent topic: Managing AI lifecycle with CPDCTL