2017. április 26., szerda

Downloading artifacts from Artifactory with JFrog CLI

You shall not pass! Unless you are a DevOps guy...or developer...tester...or a curious manager...so IT guy.

In case you wonder how to download some artefacts, files from the repository application called JFrog's Artifactory under Linux without using the UI, do not hesitate to read on. 

I faced the same problem when we started to use Artifactory besides Sonatpye Nexus. From Nexus you can download items with wget easily, but for Artifactory there is a command line interface based on REST with which it is pretty straightforward to download or upload anything and it has some other functionalities as well to manage your repos.

Sounds good? Let's see.

Installation of the jfrog cli tool to Linux is not so difficult.
  1. Log in with the user with which you want to use the tool, go to a directory which is good for you (like /tmp or /jfrog) and type: curl -fL https://getcli.jfrog.io | sh
  2.  Try out the tool like this : /tmp/jfrog h
Now you should see the help text of the tool. Easy, hm?

Next let's try to download something from Artifactory with this tool. When you type /tmp/jfrog rt dl URL, where URL is the path to the file in Artifactory starting with the repository name, not with http(s), then the tool will ask if you want to set up the configuration for Artifactory, like server url, username, etc. Choose yes and you will face five questions:

Server URL - this should be something like this : http://artifactory.company-name.com:8081/artifactory
Server ID - ask the Artifactory caretaker for this, he/she should know it
API key - you can set up a key, but it's easier now to hit enter
User - your Artifactory user name 
Password - straightforward

The tool will save this data and from that moment on you can download or upload anything without typing these credentials again (with your current Linux user). The files will be downloaded into the local directory.

Example : 

/tmp/jfrog rt dl --flat=true libs-releases-local/com/companyname/product/app/webapp/maven-metadata.xml

There are many options to use the tool, you can check these here.I used the --flat option so that no directory structure should be created for the downloaded file. 

How to download the latest version of a given artefact from Artifactory? I guess for many people this is an important question. 

If you use Maven for building and uploading the artefacts, you will have a maven-metadata.xml for each of your apps in Artifactory. In this xml all the versions are recorded. With some bash magic you can download the xml, get out the latest version of the application from it and then download the file itself as you already know which one to get. 

Here is an example how to download the latest rpm (we are using rpms on CentOS) of an app. It's written in one single line but if you prefer code readability and / or you like clean code, then feel free to create a nice .sh file for this. Time to practice reading some bash magic (I like bash!):

/tmp/jfrog rt dl --flat=true libs-releases-local/com/companyname/product/app/webapp/maven-metadata.xml && readlink -f maven-metadata.xml | xargs -I{} cat {} | grep release | cut -c 14- | rev | cut -c 11- | rev | xargs -I{} /tmp/jfrog rt dl --flat=true libs-releases-local/com/companyname/product/app/webapp/{}/*.rpm

If you don't use Maven, you have to figure out how to get the information which tells you what is the latest release. From that point it is easy to get the latest wit bash and jfrog CLI.

Good luck and may the force be with DevOps!


2016. május 13., péntek

Using awk with two actions for two conditions

You can read a lot about awk. There are a lot of tutorials about it. It's very useful tool if you want to filter file contents or simply filter/cut the output of a previous command in the shell. Yes, this is about some weird Linux stuff...

The tool usage is quite complex at first sight, but after you learn the basics of it, it becomes quite easy. It does not require too much time to use awk on a basic level.

But sometimes you face a problem which is not so straightforward for a newbie. Like I did today.

Problem: how to filter for diferrent fields (action) in two separate lines which are selected by different conditions? In other words: I want to have field 2 printed if the line contains THIS and want to have field 5 printed if the line contains THAT.

Usually we use awk like this: print field 5 if the line contains this. Or print field 4 and 6 if the line contains this and that. But in my problem the conditions and actions are different.

After investigating the case with my friend Google I found a solution: the conditional if statement! Wow...as awk is not just a command line tool, but a programming language, the solution is to think like a programmer / coder.

Here it is :

2_lines_of_output_from_another_command | awk '{if ($3 == "condition1") print $1; else print $4;}'

This is implemented for a 2 lines input because I got rid of everything else. The main point is to use if / else and you can use "if else if else"... just be careful with the different closing signs.

That's it, I hope awk is not so aw(k)ful after reading this!



2014. február 21., péntek

Facebook, Google: pay for my time!

We spend a lot of time playing with Facebook, Google, LinkedIn, etc. We - visitors, users - make these companies big, strong and...rich! Very-very rich. Without us they are nothing! 

So my question is: why don't they pay for us for making them rich? Why do we make them big at all? Time is money, we used to say, so they should compansate us somehow. 

Of course they can't pay for everyone. But they could set up some reward system for the users. The more time you spend with them, the more money you can get. And they could set a minimum level for paying. As a start, this would be great.

Sounds good?

We just have to convince Mark, Sergey and Larry. Does anyone know their email addresses? 

2014. február 20., csütörtök

What we love in testing?




Where are the hacker news on Hacker news?


When I found Hacker news (https://news.ycombinator.com/news) 1 year ago it contained a lot of hacking and security related news, blog posts. That was great! Now it doesn't. It's all about 'other' IT news and blogs like FB bought this and that, which startup raised how much money, what Tesla is planning, and so on...so boring.

Can I get my good old hacker news back?

Thanks!