0 / 0
Creating a script asset with CPDCTL in watsonx.ai Runtime
Last updated: Nov 21, 2024
Creating a script asset with CPDCTL in watsonx.ai Runtime

Learn to create a script asset with the CPDCTL command line interface.

  1. 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.

  2. Extract the downloaded archive.

    ! tar xzf cpdctl_linux_amd64.tar.gz
    
  3. Ensure that the cpdctl archive is in the current working directory and the system PATH.

    %%capture
    %env PATH={CWD}:{PATH}
    
  4. Check that the CLI is accessible.

    ! cpdctl version
    
  5. 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')
    
  6. Open your script.

    with open('<test_script>', 'w') as f:
        f.write("echo OK")
    
  7. 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.

  8. List the script assets in the project.

    ! cpdctl asset search --type-name script --query 'test.sh' --project-id {project_id}
    
  9. 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

Generative AI search and answer
These answers are generated by a large language model in watsonx.ai based on content from the product documentation. Learn more