I have uploaded the artifact to Sonatype Nexus from command line by using
MAVEN/maven/bin/mvn -X -e deploy:deploy-file -Durl=http://maven-nexus.com/nexus/content/repositories/xyz -DrepositoryId=xyz -DgroupId=com.kumar -DartifactId=peshu -Dversion=1.0.12 -Dpackaging=war -Dfile=RIGHT.war
Now I would like to delete this version (1.0.12) from command line so that I can automate this process, what is the command I can use instead of Curl.
Short anwser:
curl --request DELETE --write "%{http_code} %{url_effective}\\n" --user login:password --output /dev/null --silent http://maven-nexus.com/nexus/content/repositories/xyz/com.kumar/peshu/1.0.12
This will delete the hole GAV from your nexus.
Note:
The --write "%{http_code} %{url_effective}\\n option will return you the http code and the effective url used; idem the --output /dev/null --silent hide some verbose informations on the output,...
I am not quite sure, but I think you need a user login with admin rights on the Nexus.
Nexus version 2.5 has a Remove Releases From Repository task.
The issue of deleting released artifacts is discussed in detail here:
https://support.sonatype.com/entries/20871791-Can-I-delete-releases-from-Nexus-after-they-have-been-published-
Related
I'm using a local repository as a staging repo and would like to be able to clear the whole staging repo via REST. How can I delete the contents of the repo without deleting the repo itself?
Since I have a similar requirement in one of my environments I like to provide a possible solution approach.
It is assumed the JFrog Artifactory instance has a local repository called JFROG-ARTIFACTORY which holds the latest JFrog Artifactory Pro installation RPM(s). For listing and deleting I've created the following script:
#!/bin/bash
# The logged in user will be also the admin account for Artifactory REST API
A_ACCOUNT=$(who am i | cut -d " " -f 1)
LOCAL_REPO=$1
PASSWORD=$2
STAGE=$3
URL="example.com"
# Check if a stage were provided, if not set it to PROD
if [ -z "$STAGE" ]; then
STAGE="repository-prod"
fi
# Going to list all files within the local repository
# Doc: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-FileList
curl --silent \
-u"${A_ACCOUNT}:${PASSWORD}" \
-i \
-X GET "https://${STAGE}.${URL}/artifactory/api/storage/${LOCAL_REPO}/?list&deep=1" \
-w "\n\n%{http_code}\n"
echo
# Going to delete all files in the local repository
# Doc: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-DeleteItem
curl --silent \
-u"${A_ACCOUNT}:${PASSWORD}" \
-i \
-X DELETE "https://${STAGE}.${URL}/artifactory/${LOCAL_REPO}/" \
-w "\n\n%{http_code}\n"
echo
So after calling
./Scripts/deleteRepository.sh JFROG-ARTIFACTORY Pa\$\$w0rd! repository-dev
for the development instance, it listed me all files in the local repository called JFROG-ARTIFACTORY, the JFrog Artifactory Pro installation RPM(s), deleted them, but left the local repository itself.
You may change and enhance the script for your needs and have also a look into How can I completely remove artifacts from Artifactory?
I need to download some free plugins from wordpress website and move that folders to plugins folder via command property in the docker-compose
Is there any way to execute shell script after the docker compose is completed?
> command: apt-get install -y curl curl -SL
https://downloads.wordpress.org/plugin/advanced-custom-fields.5.7.12.zip
or a bash script for this?
The documentation says:
The command can also be a list, in a manner similar to dockerfile:
command: ["bundle", "exec", "thin", "-p", "3000"]
You can:
docker-compose run <your_service> apt-get install -y curl
docker-compose run <your_service> curl -SL https://downloads.wordpress.org/plugin/advanced-custom-fields.5.7.12.zip
You can even do it in 1 command but I'm guessing the installation is one off and you might include that in your image ;)
Hope this helps.
I need to setup a private nexus oss 3 for internal nodejs development for our company. The project dependencies have to be download from developer's computer and copy across to the private network, and then upload/publish to the private nexus instance.
We've write some scripts to pull all dependencies in .tgz format form the npm repo, and copied into the private network.
But how can I upload those .tgz files to the npm repo of my private nexus without using the GUI?
You can upload using the UI; but you choose not to use this way.
You can upload using the API; see the docs
You can upload using npm publish; eg.npm --registry=http://nxrm.local/repository/npm-hosted publish package.tgz
For someone who interest for a fast solution, here's my procedure and scripts:
create a hosted npm repo in nexus
create an account for package upload
grant 'npm Bearer Token Realm' realm to the account
run the download script for download packages from public npm repository
run the upload script for upload packages to private npm repository
script for downloading npm packages from public repository
#!/bin/bash
NODE_MODULES_PATH=./node_modules
PACKAGES_PATH=./packages
mkdir -p $PACKAGES_PATH
for url in $(grep _resolved $NODE_MODULES_PATH/**/package.json | awk -F '"' '{print $4}' | sort -u); do
if wget -c -q "$url" -P $PACKAGES_PATH; then
echo "url=$url"
else
(>&2 echo "error download url=$url")
fi
done
script for uploading npm packages to private nexus npm repository
#!/bin/bash
REPOSITORY=[REPOSITORY_URL]
PACKAGES_PATH=./packages
npm login --registry=$REPOSITORY
for package in $PACKAGES_PATH/*.tgz; do
npm publish --registry=$REPOSITORY $package
done
Note:
the packages have to be downloaded locally in the normal way
the script should be running in the project root directory
the [REPOSITORY] can be obtained in your private hosted npm repository
You can also use the rest API to manage components directly:
POST /v1/components
For instance, to upload the package my-npm-package-0.0.0.tgz to the repository npm-private use the following:
curl -u user:password -X POST "http://localhost:8081/service/rest/v1/components?repository=npm-private" -H "accept: application/json" -H "Content-Type: multipart/form-data" -F "npm.asset=#my-npm-package-0.0.0.tgz;type=application/x-compressed"
The complete live API specs can be found at endpoint /#admin/system/api
The official nexus documentation can be found at https://help.sonatype.com/repomanager3/rest-and-integration-api/components-api
I'm making an automatic script to upload a raw file in Nexus, and I need to set up the version of this file. Is this possible? I've been checking the API but it doesn't seem posible.
The command I'm currently using to upload is:
curl --proxy $my-proxy -v --user 'user:pass' --upload-file ./myRawFile 'http://12.34.56.78:1234/repository/MyRawRepo/LoL/TheUploadedFile'
This command is being used from an automatic script (and working) to upload the file, but I don't know how to set the version.
curl -k -u "xxx:xxx" -H 'Content-Type: multipart/form-data' --data-binary "#output.zip" -X PUT https://nexus.xxx.com/repository/{raw-reponame}/xxx/{version}/output.zip
Version number can be change {version}
Reading this API guide. My Artifactory version is 4.12.2.
https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-ItemProperties
It says to deploy an artifact like so.
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt" -T Desktop/myNewFile.txt
That works fine but I also want to add properties to file.txt while also uploading. I did see a separate API to set properties.
PUT /api/storage/libs-release-local/ch/qos/logback/logback-classic/0.9.9?properties=os=win,linux;qa=done&recursive=1
That works. I thought maybe it would work to do this.
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt?properties=os=win,linux;qa=done&recursive=1" -T Desktop/myNewFile.txt
It didn't work. Is it possible to upload an artifact and simultaneously set properties or does it have to be two different API calls?
I do use jfrog cli but I need an API solution.
The correct format would be something like:
curl -u myUser:myP455w0rd! -X PUT "http://localhost:8081/artifactory/my-repository/my/new/artifact/directory/file.txt;propertyA=valueA;propertyB=valueB" -T Desktop/myNewFile.txt
You can find the relevant documentation here (I agree that it was "well hidden")