If $A=R[a_1,\dots,a_p]$ is a finitely generated $R$-algebra, then it is isomorphic to a quotient $R[x_1,\dots,x_p]/I$, where $I$ is an ideal of $A$ describing the relations between the generators $a_1,\dots,a_p$ (the $a_i$'s correspond to the classes of the $x_i$'s under the isomorphism). The key point is that you must preserve the relations! In fact, if $g\in I$, then $g(a_1,\dots,a_p)=0$, so your morphism $f$ have to be compatible with that, i.e. we must have
$$g(f(a_1),\dots,f(a_p))=f(g(a_1,\dots,a_p))=0$$
since $f$ is a $R$-algebra morphism.
In your example, $\Bbb Z=\Bbb Z[1,2] \simeq \Bbb Z[x,y]/(y-2x,x-1)$ so you must have $f(2)=2f(1)$.
Now, if you preserve the relations, then $f$ exists and is unique. Indeed, if we want to have $f(a_i)=b_i$ for all $i$ then universal property of polynomial rings shows there exists a unique $R$-algebra morphism $f_1 : R[x_1,\dots,x_p]\to B$ s.t. $f_1(x_i)=b_i$ for all $i$.
Finally, preserving the relations means exactly that $f_1(I)=(0)$. Thus $f_1$ passes to the quotient and gives a morphism $f_0 : R[x_1,\dots,x_p]/I\to B$ s.t. $f_0([x_i]) = b_i$ for all $i$. By composing with the isomorphism $A=R[a_1,\dots,a_p]\to R[x_1,\dots,x_p]/I$, we obtain the existence of $f:A\to B$ s.t. $f(a_i)=b_i$ for all $i$.